Nested if-else Statement
Nested control statements mean an if-else statement inside other if or else blocks.
It is similar to an if-else statement but they are defined inside another if-else statement.
Example-
public class NestedIfElseConcept {
public static void main(String[] args) {
int age = 22;
String gender = "female";
if (age >= 18) {
if (gender == "male") {
System.out.println("You can shop in the men's section on the 3rd Floor");
} else {
System.out.println("You can shop in the women's section on 2nd Floor");
}
} else {
System.out.println("You can shop in the kid's section on 1st Floor");
}
}
}
Output:
You can shop in the women's section on 2nd Floor