Menu
×
×
Correct!

Exercise:

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

// Create a checkAge() method with an integer variable called age static void checkAge(int age) { // 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); }

Not Correct

Click here to try again.

Correct!

Next ❯
// Create a checkAge() method with an integer variable called age
static void ( ) {

  // If age is less than 18, print "Access denied"
   (  ) {
    System.out.println("Access denied"); 

  // If age is greater than 18, print "Access granted"
  }  {
    System.out.println("Access granted"); 
  }

} 

public static void main(String[] args) { 
  // Call the checkAge method and pass along an age of 20
  ();
}

  
  
  




Go to w3schools.com
Reset Score
Close This Menu

Completed 0 of 59 Exercises:

Java Syntax
Java Variables
Java Data Types
Java Operators
Java Strings
Java Math
Java Booleans
Java If...Else
Java Switch
Java Loops
Java Arrays
Java Methods
Java Classes/Objects
Java Exceptions





×

Reset the Score?

This will reset the score of ALL 59 exercises.

Are you sure you want to continue?



×

Congratulations!

You have finished all 59 Java exercises.

Share your score on facebook: