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.
Question 452
Question 453
String s = "computer";
String t = s.substring(0, s.indexOf("u")) + s.substring(5);
What value is stored in t ?Main Solution
Answer
Answer: D. s.indexOf("u") is 4, so s.substring(0, 4) is "comp". Also, s.substring(5) is "ter". Concatenating them gives "compter".
Answer: Correct: D
A
compu
B
comter
C
puter
D
compter
Answer images
Question 454
Question 455
Question 456
int p = 17 % 5;
double q = 17 / 5;
double r = q + p / 2.0;
What value is stored in r ?Main Solution
Answer
Answer: B. p is 2, and q is assigned the result of integer division 17 / 5, which is 3.0. Then p / 2.0 is 1.0, so r = 3.0 + 1.0 = 4.0.
Answer: Correct: B
A
4.5
B
4.0
C
5.0
D
3.0
Answer images
Question 457
int a = 11;
int b = 4;
double value = a / b + (a % b) / 2.0;
value after the code segment executes?Main Solution
Answer
Answer: B. a / b uses integer division, so it is 2. Also, a % b is 3, and 3 / 2.0 is 1.5. The total is 3.5.
Answer: Correct: B
A
2.75
B
3.5
C
3.0
D
4.5
Answer images
Question 458
Question 459
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.

