AP CSA Unit 2 Day 25: Iteration Selection Nested Condition
Share
Unit 2, Selection & Iteration • Cycle 2
Day 25 Advanced Practice • Harder Difficulty
Focus: Diagonal Match
Hard
Iteration + Selection (nested condition)
Advanced Practice Question
Format: Iteration + Selection (nested condition)
What is printed?
What is printed?
for (int i = 1; i <= 10; i++) {
if (i % 2 == 0) {
if (i % 3 == 0) {
System.out.print(i + " ");
}
}
}
Difficulty: Hard |
Topic: Iteration + Selection (nested condition) |
Cycle: 2 (Advanced)
Why This Answer?
Matches occur when (i, j) is (1,1), (2,2), (3,3): 3 matches total.
Common Mistake
Watch Out!
Thinking every pair increments (that would be 9) and missing the `if (i == j)` filter.
AP Exam Strategy
When there is an `if` inside nested loops, count only the iterations that satisfy the condition.
Master This Topic
This Cycle 2 HARD question tests diagonal match. Review Unit 2 concepts to build mastery of selection and iteration.
- Understanding diagonal match
- 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