Tutorialspoint examples

Learn java tutorial with examples for beginners online

If Else If Statement in Java

If else statement is used to execute one block of statements from many depends upon the condition. If condition1 is true then block of statements1 will be executed, else if condition2 is true block of statements2 is executed and so on. If no condition is true, then else block of statements will be executed.


   //Block of statements1.
}else if(condition2){
   //Block of statements2.
else if(conditionn){
   //Block of statementsn.
 //Block of statements.

Program to use if else if statement in Java.

 * Program to use if else if statement in Java program.
 * @author javawithease
public class IFELSEIFExample {	
	public static void main(String args[]){ 
		int num = 10;
		if(num == 10){
	          System.out.println("num is equals to 10.");
		}else if(num > 10){
	          System.out.println("num is greater than 10.");
		  System.out.println("num is less then 10.");


num is equals to 10.

Download this example.

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