Boolean Expressions FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

A ride stores int height = 142;. (a) Write a Java expression that is true when height is at most 140. (b) Write a Java expression that is true when height is greater than 142. (c) State the type of each expression and the value of each when height is 142.

Question 2 of 5

Trace this code.

int pile = 10;
int take = 4;
boolean a = pile - take >= 6;
boolean b = pile / take == 2;
System.out.print(a);
System.out.print(b);

(a) State the value stored in a and the value stored in b. (b) State the displayed text. (c) Explain why pile / take == 2 is true even though 10 divided by 4 is 2.5 in ordinary arithmetic.

Question 3 of 5

Compare primitive equality with reference equality.

int p = 4;
int q = 4;
String s = new String("gate");
String t = new String("gate");
String u = t;

(a) State p == q and explain. (b) State s == t and t == u and explain. (c) Write one additional boolean expression using != that is true for s and t.

Question 4 of 5

Evaluate each expression in the table using int span = 7; and char rank = 'B';. For every row, give true or false and a one-line reason.

Row Expression
1 span >= 7
2 span / 2 == 3
3 span / 2.0 == 3
4 rank > 'A'

Question 5 of 5

Contract: Input.readInt() reads the next integer the user types and returns it as int. Each call consumes one integer. Remembering Scanner methods is not required. The user types 8, then 10.

int low = Input.readInt();
int high = Input.readInt();
boolean ordered = low < high;
System.out.print(ordered);

(a) State the values stored in low, high, and ordered. (b) State the displayed text. (c) Explain why two helper calls are required, and why ordered cannot be declared as int.