Continuous Test Orchestration And Execution Platform Online

Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.

Write a Java program to demonstrate nested if … else if .. statement?

The if-else-if statement, also known as the if-else-if ladder, executes one condition from multiple statements.

Syntax


if(condition1){  
//execute the code if condition1 is true  
}else if(condition2){  
//execute the code if condition2 is true  
}  
else if(condition3){  
//execute the code if condition3 is true  
}  
...  
else{  
//execute the code if all the conditions are false  
}

Code Example

The below Java program defines a Grading system based on different scores obtained by students.


public class Example {  
public static void main(String[] args) {  
    int score=65;  
      
    if(score<50){  
        System.out.println("Fail");  
    }  
    else if(score>=50 && score<60){  
        System.out.println("D");  
    }  
    else if(score>=60 && score<70){  
        System.out.println("C");  
    }  
    else if(score>=70 && score<80){  
        System.out.println("B");  
    }  
    else if(score>=80 && score<90){  
        System.out.println("A");  
    }else if(score>=90 && score<100){  
        System.out.println("A+");  
    }else{  
        System.out.println("Invalid!");  
    }  
}  
}  
LambdaTest

Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.

Start Free Testing
LambdaTest

Earn resume-worthy Selenium certifications that help you land a top job.

Learn More
LambdaTest

Test your web or mobile apps

Test orchestration and execution cloud of 3000+ browsers and OS

Support

24/7 support

Security

Enterprise grade security

Cloud

Fastest test execution cloud