CodesJava

Easy learning with example program codes

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 codesjava
 */
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("Smaller number: " + num1);
		}
	}
}

Output:

Smaller number: 10

 

Please follow and like us:
error
Posted in Java   








Copyright © 2019 CodesJava DMCA.com Protection Status