AP® Computer Science A Selection and Iteration Multiple Choice Questions
Work through AP Computer Science A multiple-choice questions on Selection and Iteration, then check each answer against a worked solution.
Free · no sign-up Open questions need no account. Sign up or log in to open the rest.
Subtopic: Iteration Clear filter
Question 152
Question 153
Question 154
Question 155
Question 156
Question 157
Question 158
Question 159
Question 160
What is printed?
int product = 1;
for (int i = 1; i <= 6; i++) {
if (i % 2 == 0) {
product *= i;
}
}
System.out.println(product);Main Solution
The code initializes product = 1 and loops i from 1 to 6 (inclusive). Inside the loop, it multiplies product by i only when i % 2 == 0, i.e., only for even values of i.
The even values in the range [1, 6] are: 2, 4, 6.
Step-by-step:
i = 1: 1 % 2 = 1 ≠ 0 → skipi = 2: 2 % 2 = 0 → product = 1 × 2 = 2i = 3: 3 % 2 = 1 ≠ 0 → skipi = 4: 4 % 2 = 0 → product = 2 × 4 = 8i = 5: 5 % 2 = 1 ≠ 0 → skipi = 6: 6 % 2 = 0 → product = 8 × 6 = 48
So System.out.println(product) prints 48. The correct answer is A.
Teacher Explanation
This question tests students' ability to trace a loop with a conditional. The key insight is that only even values of i (2, 4, 6) contribute to the product. The product of the even integers from 2 to 6 is 2 × 4 × 6 = 48.
Education Coach Advice
When tracing loops on the AP exam, create a small table tracking the loop variable and any accumulator variable at each iteration. Pay close attention to the loop condition (i <= 6 vs i < 6) and any inner conditionals. This prevents off-by-one errors and missed conditions.
Traps
Option C (24) is a common trap: students may mistakenly compute 2 × 3 × 4 = 24, confusing which values pass the even check, or stopping the loop early. Option D (720) is 6! (factorial of 6), which would be the result if the condition were removed entirely and all values 1–6 were multiplied. Option B (36) might result from multiplying 6 × 6 or some other miscount.
Answer images
AP® and Advanced Placement® are registered trademarks of the College Board, which is not affiliated with, and does not endorse, Verityprep. Names are used for identification purposes only.

