Tutorialspoint examples

Learn java tutorial with examples for beginners online

If Statement in Java

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


   //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);


num1 Value: 10

Download this example.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status