Whenever the first number is smaller than the second, the remainder is the first number. Remember that % is the remainder and 3 goes into 2 0 times with a remainder of 2.
0
This is the number of times that 3 goes into 2 but the % operator gives you the remainder.
3
Try it. Remember that % gives you the remainder after you divide the first number by the second one.
1
This would be correct if it was 3 % 2 since 2 would go into 3 one time with a remainder of 1.
This would be true if it was System.out.println(((2 + 3) * 5) - 1), but without the parentheses the multiplication is done first.
14
This would be true if it was System.out.println(2 + (3 * (5 - 1))), but without the parentheses the multiplication is done first and the addition and subtraction are handled from left to right.
This will give a compile time error.
This will compile and run. Try it in DrJava. Look up operator precedence in Java.
16
The multiplication is done first (3 * 5 = 15) and then the addition (2 + 15 = 17) and finally the subtraction (17 - 1 = 16).
This would be true if it was b = a. What does the (int) do?
12
This is the initial value of b, but then b is assigned to be the result of casting the value in a to an integer. Casting to an integer from a double will truncate (throw away) the digits after the decimal.
10
Java does not round when converting from a double to an integer.
9
When a double is converted into an integer in Java, it truncates (throws away) the digits after the decimal.
First x is set to 3, then y is also set to 3, and next z is set to 3 * 3 = 9. Finally x is incremented to 4.
x = 0, y = 3, z = 0
You might think that y = x means that y takes xβs value, but y is set to a copy of xβs value.
x = 4, y = 4, z = 9
You might think that y = x means that if x is incremented that y will also be incremented, but y = x only sets y to a copy of xβs value and doesnβt keep them in sync.