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.
Question 322
Question 323
Question 324
Question 325
Question 326
Question 327
Question 328
int x = 4, y = 10, z = 4;
boolean a = !(x > y) && !(z == x);
boolean b = (x < y) || (z > x);
boolean c = !(x == z || y < x);
System.out.println(a + " " + b + " " + c);Main Solution
Solution:
Correct: A. a = !(4>10) && !(4==4) = true && false = false. b = (4<10) || (4>4) = true || false = true. c = !(4==4 || 10<4) = !(true || false) = false. Output: false true false.
Answer: Correct: A
Answer images
Question 329
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 330
int x = 8;
boolean c1 = (x > 5 && x < 8);
boolean c2 = !(x >= 10) || x == 8;
boolean c3 = (x < 0 || x > 12) && x != 8;
System.out.println(c1 + " " + c2 + " " + c3);Main Solution
Solution:
Correct: C. c1 = (true && false) = false. c2 = !(false) || true = true || true = true. c3 = (false || false) && false = false. Output: false true false.
Answer: Correct: C
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.

