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 = "Mohan";
int Roll = 25;
int marks = 85;
if (name.equals("Mohan") && Roll == 25) {
if (marks > 35) {
System.out.println("Mohan has been promoted to next class.");
} else {
System.out.println("Mohan needs to give re-exam.");
}
}
}
}
Output:
Mohan has been promoted to next class.