Next-Gen App & Browser
Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

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!");  
    }  
}  
}  

Test your website on 3000+ browsers

Get 100 minutes of automation test minutes FREE!!

Test Now...

KaneAI - Testing Assistant

World’s first AI-Native E2E testing agent.

...
ShadowLT Logo

Start your journey with LambdaTest

Get 100 minutes of automation test minutes FREE!!

Signup for free