Condition Statement

The Java if statement is used to test the condition. It checks boolean condition: true or false. There are various types of if statement in java.

  • if statement
  • if-else statement
  • if-else-if ladder
  • nested if statement

Sample Code

				
			
  1. //Java Program to demonstate the use of if statement.  
  2. public class IfExample {  
  3. public static void main(String[] args) {  
  4.     //defining an 'age' variable  
  5.     int age=20;  
  6.     //checking the age  
  7.     if(age>18){  
  8.         System.out.print("Age is greater than 18");  
  9.     }  
  10. }  
  11. }