Questions and Answers - University of Maryland
1. int p = 14; What is the value of p / 3 * 2?
A. 8
B. 9
C. 14
D. 4
Answer: A. 8
Rationale: Integer division yields 4 before the multiplication by two.
2. int n = -32; What is the value of n % 3?
A. -1
B. -2
C. 2
D. 1
Answer: B. -2
Rationale: For integer remainder the result has the dividend’s sign when it is nonzero.
3. int n = 6; int m = n++ + ++n; What is the value of m + ":" + n?
A. 14:8
B. 13:8
C. 14:7
D. 15:8
Answer: A. 14:8
Rationale: The left operand yields the old value and increments n. The right operand increments it
again before yielding.
,4. What is the decimal value of the binary Java literal 0b110100?
A. 52
B. 26
C. 56
D. 104
Answer: A. 52
Rationale: Sum the powers of two corresponding to positions with a one digit.
5. int n = 5; int score = 0; if (n <= 5) score += 3; else if (n <= 7) score += 7; What is the value of score?
A. 7
B. 0
C. 3
D. 10
Answer: C. 3
Rationale: The first condition is true, so the else-if body does not execute.
6. int n = 3; boolean ok = n < 3 && ++n > 0; What is the value of n?
A. 5
B. 4
C. 3
D. 2
Answer: C. 3
Rationale: The equality boundary makes the left comparison false. Conditional AND skips the
increment.