Notice: Constant WP_MEMORY_LIMIT already defined in /home/javawith/public_html/ on line 107

Notice: Constant WP_MAX_MEMORY_LIMIT already defined in /home/javawith/public_html/ on line 108
If else statement in java - CodesJava


Easy learning with example program codes

If Else Statement in Java

Notice: Undefined variable: footnotelist in /home/javawith/public_html/ on line 475

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   

Core Java Tutorial

Copyright © 2019 CodesJava Protection Status