Unit 2 Cycle 2 Day 14: Iteration + Selection (Filtering)

Unit 2, Selection & Iteration • Cycle 2
Day 14 Advanced Practice • Harder Difficulty
Focus: Loop Filtering Hard Iteration + Selection (Filtering)

Advanced Practice Question

Format: Iteration + Selection (Filtering)

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

"apcs-keyword">for ("apcs-keyword">int i = "apcs-number">1; i <= "apcs-number">6; i++)
{
    "apcs-keyword">if (i % "apcs-number">2 != "apcs-number">0)
    {
        sum += i;
    }
}

System.out.println(sum);
Difficulty: Hard  |  Topic: Iteration + Selection (Filtering)  |  Cycle: 2 (Advanced)
Why This Answer?

Only odd i values are added: 1 + 3 + 5 = 9.

Common Mistake
Watch Out!

Accidentally adding evens because of a flipped condition (`== 0` vs `!= 0`).

AP Exam Strategy

When filtering in a loop, identify which values pass the `if` condition.

Master This Topic

This Cycle 2 HARD question tests loop filtering. Review Unit 2 concepts to build mastery of selection and iteration.

  • Understanding loop filtering
  • 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.