AP CSA Unit 2 Day 28: Iteration Nested Loop Accumulation
Share
Unit 2, Selection & Iteration • Cycle 2
Day 28 Advanced Practice • Harder Difficulty
Focus: Variable Inner Bound
Hard
Iteration (nested loop accumulation)
Advanced Practice Question
Format: Iteration (nested loop accumulation)
What is printed?
What is printed?
int sum = 0;
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
sum += i * j;
}
}
System.out.println(sum);
Difficulty: Hard |
Topic: Iteration (nested loop accumulation) |
Cycle: 2 (Advanced)
Why This Answer?
x increments 1 time when i=1, 2 times when i=2, and 3 times when i=3. Total = 1+2+3 = 6.
Common Mistake
Watch Out!
Assuming inner loop always runs 3 times instead of depending on i.
AP Exam Strategy
When the inner bound depends on i, compute iterations for each i separately.
Master This Topic
This Cycle 2 HARD question tests variable inner bound. Review Unit 2 concepts to build mastery of selection and iteration.
- Understanding variable inner bound
- 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