If Statement in Java

 
If statement is used to execute a block of statements if specified condition is true.

Syntax:

if(condition){
   //Block of statements.
}

Program to use if statement in Java.

/**
 * Program to use if statement in Java.
 * @author javawithease
 */
public class IFExample {	
	public static void main(String args[]){ 
		int num1 = 10;
		int num2 = 20;
		if(num1 < num2){
		  //Print num1 if num1 < num2.
	          System.out.println("num1 Value: " + num1);
		}
	}
}

Output:

num1 Value: 10

Download this example.