AP CSA Unit-Level MCQ
Boolean Operators
Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.
What boolean operators covers
Boolean expressions combine comparisons with && (and), || (or), and ! (not). Precedence runs ! first, then &&, then ||, so a || b && c evaluates as a || (b && c). De Morgan laws give the equivalences you need for negation: !(a && b) is !a || !b, and !(a || b) is !a && !b. Recognizing that two differently written conditions are logically identical is a tested skill in itself.
Where students lose points
Negating a compound condition by flipping only the comparisons and leaving && as && is the classic mistake. Students also misread precedence and insert parentheses that change meaning. A related trap is negating a range test: the opposite of x > 0 && x < 10 is x <= 0 || x >= 10.
How it shows up on the AP exam
Core Unit 2 content. Equivalent-expression questions are a reliable MCQ format, and clean Boolean logic is what keeps FRQ conditionals from failing edge cases.
For practice use only.
Boolean Operators MCQ Practice
AP CSA Boolean operator practice: &&, ||, and ! precedence, De Morgan equivalences, and negating compound conditions correctly on the exam.
Answered 0 of 15
Choose one answer.
Code Tracing 01 - Boolean Operators: track the final printed value.
int likes = 18;
int shares = 5;
int comments = 3;
boolean flag = (likes > 20 && shares < 10) || comments == 4;
System.out.print(flag);All 15 boolean operators questions
Work through the interactive quiz above first. This is the full boolean operators question set with worked solutions, so students can review any question after attempting it.
1.Code Tracing 01 - Boolean Operators: track the final printed value.
int likes = 18; int shares = 5; int comments = 3; boolean flag = (likes > 20 && shares < 10) || comments == 4; System.out.print(flag);- The code does not compile.
- A runtime exception is thrown.
- false
- true
Show worked solution
Correct answer: false
The && part is evaluated as a group before it is combined with the final || condition.
2.Code Tracing 12 - Boolean Operators: follow the variable updates.
int a = 26; int b = 5; int c = 7; boolean result = !(a % 2 == 0 && c > b); System.out.print(result);- true
- The code does not compile.
- A runtime exception is thrown.
- false
Show worked solution
Correct answer: false
The expression inside the parentheses is evaluated first; ! reverses the final boolean value.
3.Code Tracing 28 - Boolean Operators: trace the branch and loop path.
int score = 38; boolean inRange = score >= 20 && score <= 40; System.out.print(inRange);- false
- The code does not compile.
- A runtime exception is thrown.
- true
Show worked solution
Correct answer: true
For an inclusive range, both endpoint comparisons must be true.
4.Code Tracing 39 - Boolean Operators: watch the index changes.
int total = 46; int divisor = 5; int limit = 5; boolean ok = divisor != 0 && total / divisor > limit; System.out.print(ok);- true
- false
- The code does not compile.
- A runtime exception is thrown.
Show worked solution
Correct answer: true
The divisor check is first. Since it is true in this trace, Java evaluates the integer division comparison.
5.Code Tracing 50 - Boolean Operators: evaluate the state change step by step.
int a = 54; int b = 7; int c = 7; int d = 3; boolean result = a < c || c - b > d; System.out.print(result);- A runtime exception is thrown.
- false
- true
- The code does not compile.
Show worked solution
Correct answer: false
The || expression is true when at least one side is true.
6.What is printed by the following code segment?
int a = 5; int b = 0; boolean r = b != 0 && a / b > 1; boolean s = b == 0 || a / b > 1; System.out.print(r + " " + s);- false true
- true true
- false false
- true false
Show worked solution
Correct answer: false true
Both expressions short-circuit before the division runs, so neither throws even though b is zero.
7.What is printed by the following code segment?
boolean p = true; boolean q2 = false; System.out.print((p && !q2) == (p || q2));- false
- true
- The code does not compile.
- 1
Show worked solution
Correct answer: true
The left side is true and the right side is also true, so comparing the two booleans gives true.
8.What is printed by the following code segment?
int x = 4; boolean r = !(x > 2 && x < 10) || x % 2 == 0; System.out.print(r);- false
- The code does not compile.
- true
- 4
Show worked solution
Correct answer: true
The negated conjunction is false, but the second operand is true because 4 is even, so || makes the whole expression true.
9.What is printed by the following code segment?
int n = 12; System.out.print(n % 2 == 0 != (n % 3 == 0));- true
- The code does not compile.
- 12
- false
Show worked solution
Correct answer: false
Both divisibility tests are true, so comparing them with != gives false.
10.Which expression is true exactly when n is divisible by 4 but not by 3?
- n % 4 == 0 && n % 3 != 0
- n % 4 == 0 || n % 3 != 0
- !(n % 4 == 0 && n % 3 == 0)
- n % 12 != 0
Show worked solution
Correct answer: n % 4 == 0 && n % 3 != 0
Both conditions must hold at once, so && is required and the second test must be a negation.
11.Which expression is equivalent to !(a || (b && !c))?
- !a || (!b && c)
- !a && (!b || c)
- !a && !b && c
- a && !b && c
Show worked solution
Correct answer: !a && (!b || c)
Applying De Morgan twice turns the outer || into && and the inner && into ||, and the double negation on c cancels.
12.What is printed by the following code segment?
int a = 3; int b = 3; boolean r = a++ > 3 && b++ > 2; System.out.print(r + " " + a + " " + b);- false 4 4
- true 4 4
- false 4 3
- false 3 3
Show worked solution
Correct answer: false 4 3
The left operand is false, so && skips the right one entirely and b is never incremented.
13.What is printed by the following code segment?
int a = 3; int b = 3; boolean r = a++ > 2 || b++ > 2; System.out.print(r + " " + a + " " + b);- true 4 4
- false 4 3
- true 3 3
- true 4 3
Show worked solution
Correct answer: true 4 3
The left operand is true, so || skips the right one and b keeps its value. Compare this with the && version.
14.What is printed by the following code segment?
boolean a = true; boolean b = false; boolean c = true; System.out.print(a || b && c ? "x" : "y");- x
- y
- The code does not compile.
- true
Show worked solution
Correct answer: x
The && binds tighter, so the condition is a || (b && c), which is true, and the conditional operator selects x.
15.Which expression is true exactly when exactly two of the three booleans p, q, and r are true?
- p && q && r
- (p && q && !r) || (p && !q && r) || (!p && q && r)
- (p && q) || (q && r) || (p && r)
- p != q != r
Show worked solution
Correct answer: (p && q && !r) || (p && !q && r) || (!p && q && r)
Each disjunct names one of the three ways to have exactly two true, and the third choice is also true when all three are true.
