If Else Statement in Java

 
If else statement is used to execute either of two block of statements depends upon the condition. If condition is true then if block will execute otherwise else block will execute.

Syntax:

if(condition){
   //Block of statements1.
}else{
   //Block of statements2.
}

Program to use if else statement in Java.

/**
 * Program to use if else statement in Java program.
 * @author javawithease
 */
public class IFELSEExample {	
	public static void main(String args[]){ 
		int num = 10;
		if(num == 10){
	          System.out.println("num is equals to 10.");
		}else{
	          System.out.println("num is not equals to 10.");
		}
	}
}

Output:

num is equals to 10.

Download this example.