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 statement?

The if-else statement executes a block of statements if a condition is true. If the specified condition is false, it executes another block of statements. The if-else statement comes under JavaScript's conditional statements, which can be used to perform specified actions based on different conditions.

Syntax


if(condition){  
//execute the statement if condition is true  
}
else{  
//execute the statement if condition is false 
}  

Code Example

The below Java program checks whether a number is even or odd.


public class EvenOdd {  
public static void main(String[] args) {  
    int num=12;  
    if(num%2==0){  
        System.out.println("Even Number");  
    }
    else{  
        System.out.println("Odd Number");  
    }  
}  
}  

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