Nested if statement in Java

Nested if statement means nesting a if statement inside a if statement.

General Syntax

if(condition or expression) {

if(condition or expression) {

//body or statement

}

}

Example

public class NestedStatements {

public static void main(String args[]) {

int a=10,b=15,c=20;

if(b>a){

if(c>a){

System.out.print("A is the smallest");

}

}

}

}

Try In Editor

Output

A is the smallest


We can also nest a if-else or else-if ladder inside a if-else or else-if ladder.