AP® Computer Science A Multiple Choice Questions
Work through AP Computer Science A multiple-choice questions unit by unit, 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.
Multiple choice
Unit 2: Selection and Iteration
Question 1082
Multiple choice
Unit 2: Selection and Iteration
Question 1083
Multiple choice
Unit 2: Selection and Iteration
Consider the following code segment.
int n = 81;
int count = 0;
while (n > 1)
{
if (n % 3 == 0)
n = n / 3;
else
n = n - 1;
count++;
}
What value is stored in count after the loop terminates?
Pick an answer, then check it. The solution opens in a window.
ACorrect answer
Main Solution
Answer
Answer: A. Because each value remains divisible by 3, the path is 81 → 27 → 9 → 3 → 1. That is 4 iterations.
Answer: Correct: A
A
4
B
5
C
3
D
6
Answer images
Question 1084
Multiple choice
Unit 2: Selection and Iteration
Question 1085
Multiple choice
Unit 2: Selection and Iteration
Consider the following method.
public static int process(int n)
{
int result = 0;
while (n > 0)
{
result = result + n % 10;
n = n / 100;
}
return result;
}
What value is returned by process(58364) ?
Pick an answer, then check it. The solution opens in a window.
CCorrect answer
Main Solution
Answer
Answer: C. The method adds the last digit, then removes the last two digits. Starting with 58364, it adds 4, then 3 from 583, then 5 from 5. The total is 12.
Answer: Correct: C
A
26
B
17
C
12
D
10
Answer images
Question 1086
Multiple choice
Unit 2: Selection and Iteration
Question 1087
Multiple choice
Unit 2: Selection and Iteration
Question 1088
Multiple choice
Unit 2: Selection and Iteration
Question 1089
Multiple choice
Unit 2: Selection and Iteration
Question 1,081 of 2,811
Page 109 of 282
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.

