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 4: Data Collections
Question 2782
Multiple choice
Unit 4: Data Collections
Question 2783
Multiple choice
Unit 4: Data Collections
Question 2784
Multiple choice
Unit 4: Data Collections
Question 2785
Multiple choice
Unit 4: Data Collections
Question 2786
Multiple choice
Unit 4: Data Collections
Question 2787
Multiple choice
Unit 4: Data Collections
Question 2788
Multiple choice
Unit 4: Data Collections
Question 2789
Multiple choice
Unit 4: Data Collections
Question 2790
Multiple choice
Unit 4: Data Collections
Consider the following method.
public static int g(int n)
{
if (n == 1)
return 1;
if (n % 2 == 0)
return g(n / 2);
return 1 + g(n - 1);
}
What value is returned by g(12) ?
Pick an answer, then check it. The solution opens in a window.
ACorrect answer
Main Solution
Answer
Answer: A. Since 12 is even, g(12) = g(6). Since 6 is even, g(6) = g(3). Then g(3) = 1 + g(2) = 1 + g(1) = 2.
Answer: Correct: A
A
2
B
3
C
4
D
1
Answer images
Question 2,781 of 2,811
Page 279 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.

