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 182
Question 183
Question 184
Question 185
Question 186
Question 187
Question 188
Question 189
int n = 100;
int count = 0;
while (n > 1)
{
n = n / 2;
count++;
}
System.out.println(count);Main Solution
Solution:
Correct: B. Trace of n: 100 → 50 → 25 → 12 → 6 → 3 → 1. The loop runs 6 times (the condition n>1 becomes false when n = 1).
Answer: Correct: B
Answer images
Question 190
int count = 0;
for (int i = 0; i < 5; i++)
{
for (int j = i; j < 5; j++)
{
count++;
}
}
System.out.println(count);Main Solution
Solution:
Correct: D. Inner iterations per i: i=0 → 5, i=1 → 4, i=2 → 3, i=3 → 2, i=4 → 1. Total = 5+4+3+2+1 = 15.
Answer: Correct: D
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.

