AP CSA Unit 2 Day 4: Selection Nested If Else
Share
Unit 2, Selection & Iteration • Cycle 2
Day 4 Advanced Practice • Harder Difficulty
Focus: Nested Conditionals
Hard
Selection (Nested if / else)
Advanced Practice Question
Format: Selection (Nested if / else)
What is printed?
What is printed?
int x = 10;
int y = 20;
if (x > 5) {
if (y > 15) {
System.out.println("Both");
} else {
System.out.println("X only");
}
} else {
System.out.println("Neither");
}
Difficulty: Hard |
Topic: Selection (Nested if / else) |
Cycle: 2 (Advanced)
Why This Answer?
`x > 3` is true, so the inner `if` runs. `y > 3` is false, so it prints `B`.
Common Mistake
Watch Out!
Forgetting the inner condition still matters once you enter the outer block.
AP Exam Strategy
Trace outer condition first, then evaluate the inner condition only if you enter the block.
Master This Topic
This Cycle 2 HARD question tests nested conditionals. Review Unit 2 concepts to build mastery of selection and iteration.
- Understanding nested conditionals
- Tracing code execution accurately
- Avoiding common pitfalls
Ready for More Challenges?
Cycle 2 questions prepare you for the hardest AP CSA exam questions.
Study Games Practice FRQs