Java Beginner Tutorial #3 : If statement

If Statement

test if condition is True or False

public class IfExample {  
public static void main(String[] args) {  
    //defining an 'age' variable  
    int Customer1 =21;  
    //checking the age  
    if(Customer1 >=21){  
        System.out.print("Customer1 can Enter, is 21+");  
    }  
}  
}  
Output :
Customer1 can Enter, is 21+

Else

Tells the program what to do if condition is False

public class ElseExample {  
public static void main(String[] args) {  
     
    int Customer1 =21;  
    int Customer2 =19;
    
    if(Customer1 >=21)
    {  
        System.out.print("Customer1 can Enter, is 21+");  
    }else{
    	System.out.print("Customer1 Can Not Enter");
    }  
	if(Customer2 >=21)
    {  
        System.out.print("Customer2 can Enter, is 21+");  
    }    
  	else{
  		System.out.print("Customer2 Can Not Enter");
  	}
  }  
}  

Nested If

If statement with in a If statement

public class Nested_IfExample {    
public static void main(String[] args) {    
      
    int Inventory=165;  
    int Ordered=123;    
    //applying condition on age and weight  
    if(Inventory>=75){    
        if(Inventory>Ordered){  
            System.out.println("Efficient Supplies");  
        }    
    }    
} 
Click here for Part Four :List