If Statements – Practice & Nested
Practice with nested if blocks, combine conditions safely, and compare strings correctly.
Lesson Goals
Goals: Practice if/else, write nested checks, and compare strings safely.
- Nested if for multi-step decisions
- Combine conditions with && and ||
- Use equals for string comparison
Nested If
Nested if runs an inner check only when the outer condition is true.
public class Main {
public static void main(String[] args) {
int age = 16;
if (age >= 0) {
if (age < 18) {
System.out.println("Minor");
} else {
System.out.println("Adult");
}
}
}
}
All lessons in this course
- If Statements – Basics
- If Statements – Practice & Nested
- Common Pitfalls & Debugging Messages