AP Computer Science A · Topic 3.1
Boolean Expressions Practice
Part of Boolean Expressions and if Statements.
Practice questions
24
Sample questions
5 of 24 — sign in to practice the rest with adaptive difficulty and mastery tracking.
Sample 1difficulty 1/5
Which evaluates to <code>true</code>?
- A
5 != 5
- Bcheck_circle
5 <= 5
- C
5 > 7
- D
5 == 6
Why
<code><=</code> is "less than or equal"; 5 ≤ 5 is true.
- A
Sample 2difficulty 1/5
int a = 5; int b = 5; if (a <= b) { System.out.println("yes"); } else { System.out.println("no"); }What is printed?
- A
true
- B
false
- C
no
- Dcheck_circle
yes
Why
a <= b means "a less than or equal to b". 5 <= 5 is true, so "yes" prints.
- A
Sample 3difficulty 2/5
Which assigns <code>true</code> to <code>b</code>?
- Acheck_circle
boolean b = 5 > 3;
- B
boolean b = 5 = 3;
- C
boolean b = 5;
- D
boolean b = (5 = 3);
Why
<code>></code> is comparison; 5 > 3 evaluates to <code>true</code>. <code>=</code> is assignment, not comparison.
- A
Sample 4difficulty 2/5
int x = 3; int y = 3; if (x == y) { System.out.println("equal"); } else { System.out.println("not equal"); }What is printed?
- A
not equal
- Bcheck_circle
equal
- C
compile error
- D
true
Why
== is the equality comparison operator. x and y both equal 3, so the condition is true and "equal" is printed.
- A
Sample 5difficulty 2/5
int a = 5; int b = 5; if (a != b) { System.out.println("X"); } else { System.out.println("Y"); }What is printed?
- Acheck_circle
Y
- B
X
- C
true
- D
false
Why
a and b are equal, so a != b is false, and the else branch prints "Y".
- A