Question 1 of 5
A greenhouse logger stores int temp = 19;. (a) Write a Java expression that is true when temp is at least 18. (b) Write a Java expression that is true when temp is not 19. (c) State the type of each expression.
Responses receive AI feedback against a rubric after submission. Scores are practice estimates.
A greenhouse logger stores int temp = 19;. (a) Write a Java expression that is true when temp is at least 18. (b) Write a Java expression that is true when temp is not 19. (c) State the type of each expression.
Trace this code.
int left = 8;
int right = 3;
boolean a = left != right;
boolean b = left == right + 5;
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 how right + 5 is used in the == comparison.
A program compares primitives and objects.
int n = 6;
int m = 6;
String x = new String("lime");
String y = new String("lime");
String z = x;
(a) State the boolean value of n == m and explain why. (b) State the boolean value of x == y and of x == z and explain the difference. (c) Explain why x < y is not a valid comparison of these String references.
Evaluate each expression in the table using int coins = 11; and int pack = 4;. For every row, give true or false and a one-line reason.
| Row | Expression |
|---|---|
| 1 | coins > pack |
| 2 | coins / pack == 2 |
| 3 | coins / pack == 2.75 |
| 4 | coins <= 11 |
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 15.
int goal = 12;
int actual = Input.readInt();
boolean met = actual >= goal;
System.out.print(met);
(a) State the value stored in actual and the value stored in met. (b) State the displayed text. (c) Identify which statement receives input, and explain why met has type boolean.