AP Computer Science A · Topic 3.5
Compound Boolean Expressions Practice
Part of Boolean Expressions and if Statements.
Practice questions
33
Sample questions
5 of 33 — sign in to practice the rest with adaptive difficulty and mastery tracking.
Sample 1difficulty 1/5
boolean b = true; System.out.println(!b);What is printed?
- Acheck_circle
false
- B
true
- C
!true
- D
1
Why
The ! operator negates a boolean value. !true evaluates to false.
- A
Sample 2difficulty 2/5
int a = 5; int b = 10; boolean result = (a < b) && (b > 0); System.out.println(result);What is printed?
- Acheck_circle
true
- B
false
- C
5
- D
10
Why
Both (a < b) which is (5 < 10) = true and (b > 0) which is (10 > 0) = true. true && true = true.
- A
Sample 3difficulty 2/5
if (!(x < 5)) { return true; } return false;Which expression is equivalent to !(x < 5)?
- A
x != 5
- B
x <= 5
- C
x > 5
- Dcheck_circle
x >= 5
Why
The negation of x < 5 is x >= 5 (x is at least 5).
- A
Sample 4difficulty 2/5
int n = 50; if (n >= 0 && n <= 100) { System.out.println("valid"); } else { System.out.println("invalid"); }What is printed?
- Acheck_circle
valid
- B
0
- C
invalid
- D
100
Why
50 is between 0 and 100 inclusive, so both parts of the && are true, and "valid" is printed.
- A
Sample 5difficulty 2/5
<code>(5 > 3) && (4 < 2)</code> evaluates to
- A
1
- B
Compile error
- Ccheck_circle
false
- D
true
Why
AND requires both true; second is false → result false.
- A