0% found this document useful (0 votes)
73 views

Exercises Java

This code defines a checkAge method that takes an integer parameter called age. The method prints "Access denied" if age is less than 18, and "Access granted" if age is greater than or equal to 18. The main method calls checkAge, passing in the value 20.

Uploaded by

blabla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

Exercises Java

This code defines a checkAge method that takes an integer parameter called age. The method prints "Access denied" if age is less than 18, and "Access granted" if age is greater than or equal to 18. The main method calls checkAge, passing in the value 20.

Uploaded by

blabla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Exercise:

Follow the comments to insert the missing parts of the code below:

// Create a checkAge() method with an integer variable


called age
checkAge int age
static void ( ) {

// If age is less than 18, print "Access denied"


if age < 18
( ) {
System.out.println("Access denied");

// If age is greater than 18, print "Access granted"


else
} {
System.out.println("Access granted");
}

public static void main(String[] args) {


// Call the checkAge method and pass along an age of 20
checkAge 20
( );
}

You might also like