Unit 2 Cycle 2 Day 20: Iteration (accumulation)

Unit 2, Selection & Iteration • Cycle 2
Day 20 Advanced Practice • Harder Difficulty
Focus: Zero-Based Accumulation Hard Iteration (accumulation)

Advanced Practice Question

Format: Iteration (accumulation)

What is printed?
"apcs-keyword">int s = "apcs-number">0;

"apcs-keyword">for ("apcs-keyword">int i = "apcs-number">0; i <= "apcs-number">4; i++)
{
    s += i;
}

System.out.println(s);
Difficulty: Hard  |  Topic: Iteration (accumulation)  |  Cycle: 2 (Advanced)
Why This Answer?

The loop adds 0 + 1 + 2 + 3 + 4 = 10.

Common Mistake
Watch Out!

Forgetting that starting at 0 still includes 4 because of `<= 4`.

AP Exam Strategy

Check both the start value and whether the end is inclusive.

Master This Topic

This Cycle 2 HARD question tests zero-based accumulation. Review Unit 2 concepts to build mastery of selection and iteration.

  • Understanding zero-based accumulation
  • Tracing code execution accurately
  • Avoiding common pitfalls
View Unit 2 Study Guide

Ready for More Challenges?

Cycle 2 questions prepare you for the hardest AP CSA exam questions.

Study Games Practice FRQs
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.