Easy learning with example program codes

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.


   //Block of statements1.
   //Block of statements2.

Program to use if else statement in Java.

 * Program to use if else statement in Java program.
 * @author codesjava
public class IFELSEExample {	
	int num1 = 20;
	int num2 = 15;
	if(num1 < num2){
	    //Print num1 if num1 < num2.
	    System.out.println("Smaller number: " + num1);
        }else {
            //Print num2 if num2 < num1.
	    System.out.println("Smaller number: " + num2);


Smaller number: 15


Please follow and like us:
Posted in Java   

Copyright © 2020 CodesJava Protection Status