Unit 2 Cycle 2 Day 27: Iteration + Selection (nested filtering)

Unit 2, Selection & Iteration • Cycle 2
Day 27 Advanced Practice • Harder Difficulty
Focus: Nested Filtering Hard Iteration + Selection (nested filtering)

Advanced Practice Question

Format: Iteration + Selection (nested filtering)

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

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

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

For each i, odd j values are 1 and 3, so c increments 2 times per outer iteration. Two outer iterations → 4.

Common Mistake
Watch Out!

Counting all j values (4 per i) instead of only odd j values (2 per i).

AP Exam Strategy

When a condition filters iterations, count only the values that pass.

Master This Topic

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

  • Understanding nested 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.