AP Computer Science A Unit 2 Exam (2025) - Selection & Iteration
AP Computer Science A Unit 2 Exam (2025) - Selection & Iteration
Looking for written practice? SKIP TO: AP CSA Unit 2 Free-Response Practice (FRQs) to strengthen your loop and conditional reasoning.
This AP Computer Science A Unit 2 exam is designed for the new 2025 AP CSA 4-Unit curriculum and focuses on decision-making and repetition, two of the most heavily tested skills on the AP exam.
Unit 2 builds on foundational Java syntax by teaching programs how to make decisions using boolean expressions and repeat actions using loops. These skills appear extensively in both multiple-choice questions and free-response questions.
This assessment includes high-difficulty multiple-choice questions modeled after:
- ✔ The official AP Computer Science A Course and Exam Description (CED)
- ✔ Barron's AP CSA loop-tracing and logic challenges
- ✔ CodeHS and AP Classroom progress-check style problems
- ✔ Common AP CSA mistakes involving conditionals, short-circuit logic, and loop errors
The questions emphasize precise tracing, boolean reasoning, and the ability to recognize loop patterns and pitfalls under exam pressure.
- Boolean expressions and logical operators (
&&,||,!) - Relational operators and compound conditions
- if, else-if, else, and nested conditionals
- Short-circuit evaluation
- while loops and for loops
- Common loop patterns (counting, summing, searching)
- Off-by-one errors and infinite loops
- Tracing and debugging selection + iteration logic
At the bottom of this exam, you will complete two concise Free-Response Questions (FRQs) written in the style of AP Classroom Progress Checks, where you will write and test code using a Java sandbox.
AP Computer Science A - Unit 2 Exam
Selection & Iteration (High Difficulty)
Section I: Multiple Choice (30 Questions)
Question 1
What is printed?
int x = 0;
if (x != 0 && 10 / x > 1)
System.out.println("Yes");
else
System.out.println("No");
Short-circuit evaluation prevents division by zero.
Question 2
How many times does the loop execute?
for (int i = 2; i <= 20; i += 3)
System.out.print(i + " ");
2,5,8,11,14,17 → 6 iterations.
Question 3
Which condition checks if x is outside 1-10 inclusive?
Outside a range requires OR.
Question 4
What is printed?
int n = 5;
while (n > 0) {
n -= 2;
System.out.print(n + " ");
}
Loop stops when n becomes negative.
Question 5
What is printed?
String s = "java";
for (int i = 0; i < s.length(); i++)
if (s.charAt(i) == 'a')
System.out.print(i + " ");
'a' appears at indices 1 and 3.
Question 6
Which statement about loops is TRUE?
All correct loops must terminate.
Question 7
What is printed?
int x = 10;
if (x > 5)
if (x < 8)
System.out.println("A");
else
System.out.println("B");
Else pairs with the nearest if.
Question 8
What is printed?
int sum = 0;
for (int i = 1; i <= 4; i++)
sum += i;
System.out.println(sum);
1+2+3+4 = 10.
Question 9
Which expression generates a random integer from 1-6 inclusive?
Correct inclusive random pattern.
Question 10
What is printed?
String s = "hello"; s.toUpperCase(); System.out.println(s);
Strings are immutable.
Question 11
What is printed?
int x = 1;
while (x < 10) {
x *= 2;
}
System.out.println(x);
1 → 2 → 4 → 8 → 16, then condition fails.
Question 12
Which expression is equivalent to !(a >= 5 && a <= 10)?
De Morgan's Law: NOT (AND) → OR of negations.
Question 13
What is printed?
int count = 0;
for (int i = 1; i <= 10; i++) {
if (i % 4 == 0)
count++;
}
System.out.println(count);
Only 4 and 8 are divisible by 4.
Question 14
What is printed?
int x = 3;
for (int i = 0; i < x; i++) {
x--;
System.out.print(i + " ");
}
x decreases, causing early termination.
Question 15
Which statement about while loops is TRUE?
If the condition starts false, the loop never runs.
Question 16
What is printed?
String s = "APCSA";
for (int i = 1; i < s.length(); i += 2)
System.out.print(s.charAt(i));
Indices 1,3,5 → P, S, A.
Question 17
What causes an infinite loop?
If nothing changes, the condition never becomes false.
Question 18
What is printed?
int x = 10;
if (x < 5 || x / 2 > 3)
System.out.println("A");
else
System.out.println("B");
10 / 2 = 5, which is greater than 3.
Question 19
What is printed?
int n = 7;
int count = 0;
while (n > 0) {
n -= 3;
count++;
}
System.out.println(count);
7 → 4 → 1 → -2 → 3 iterations.
Question 20
Which condition checks if x equals 2, 4, or 6?
Each equality must be explicitly stated.
Question 21
What is printed?
for (int i = 5; i > 0; i--) {
if (i == 3)
break;
System.out.print(i + " ");
}
Loop stops when i equals 3.
Question 22
Which best describes short-circuit evaluation?
Evaluation stops once result is known.
Question 23
What is printed?
int sum = 0;
for (int i = 1; i <= 3; i++)
for (int j = 1; j <= 2; j++)
sum++;
System.out.println(sum);
3 x 2 = 6 total iterations.
Question 24
What is printed?
int x = 1;
while (x <= 5) {
System.out.print(x + " ");
x += 2;
}
x increases by 2 each time.
Question 25
Which loop counts from 10 down to 1?
Starts at 10 and decrements to 1.
Question 26
What is printed?
int x = 4;
int y = 0;
while (x > 0) {
y++;
x /= 2;
}
System.out.println(y);
4 → 2 → 1 → 0 → 3 iterations.
Question 27
Which statement about break is TRUE?
break exits the innermost loop immediately.
Question 28
What is printed?
int count = 0;
for (int i = 1; i <= 20; i++) {
if (i % 2 == 0 && i % 5 == 0)
count++;
}
System.out.println(count);
10 and 20 satisfy both conditions.
Question 29
What is printed?
int i = 0;
while (i < 5)
System.out.print(i++);
Post-increment prints before incrementing.
Question 30
Which scenario BEST uses a sentinel-controlled loop?
Sentinel loops terminate on a specific value.
Š Test Summary
Section II: Free Response (Progress Check Style)
FRQ 1 - Loop Logic
Write a method countMultiples that returns how many integers between start and end inclusive are divisible by k.
public static int countMultiples(int start, int end, int k)
FRQ 2 - String Traversal
Write a method hasAlternatingCase that returns true if a string alternates uppercase and lowercase letters starting at index 0.
public static boolean hasAlternatingCase(String s)
Next Step: Unit 3
Once you are comfortable with selection and iteration, you are ready to move on to AP Computer Science A Unit 3 - Class Creation
Want to test everything together? Try our > Full AP CSA Practice Exam
Stuck on loops or conditionals? Explore AP CSA tutoring for loops and conditionals