Notice: Constant WP_MEMORY_LIMIT already defined in /home/javawith/public_html/codesjava.com/wp-config.php on line 107

Notice: Constant WP_MAX_MEMORY_LIMIT already defined in /home/javawith/public_html/codesjava.com/wp-config.php on line 108
If else statement in java - CodesJava

CodesJava

Easy learning with example program codes

If Else Statement in Java


Notice: Undefined variable: footnotelist in /home/javawith/public_html/codesjava.com/wp-content/plugins/latex2html/inc/core.php 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.

Syntax:

if(condition){
   //Block of statements1.
}else{
   //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);
        }
}

Output:

Smaller number: 15

 

Please follow and like us:
error
Posted in Java   

Core Java Tutorial








Copyright © 2019 CodesJava DMCA.com Protection Status