Nested if Statements

 

Nested if Statements

if statements inside other if statements are called nested if statements.

Example:

public class Nested {
    public static void main(String[] args) {
        String name = "Coco";
        int Roll = 25;
        int marks = 85;
        if (name == "Coco" && Roll == 25) {
            if (marks > 35) {
                System.out.println("Coco has been promoted to next class.");
            } else {
                System.out.println("Coco needs to give re-exam.");
            }
        }
    }
}


Output:

Coco has been promoted to next class.