Question 1
What does this print? ```java public class Main { public static void main(String[] args) { System.out.println(5 / 2 + " " + 5 % 2 + " " + 5.0 / 2); } } ```
A. 2.5 1 2.5
Shows 2.5 for the first result, which would require a floating-point operand in 5 / 2, but both operands there are int.
B. 2.5 0 2.5
Shows 0 for the remainder, but 5 % 2 is 1; only an even dividend would give remainder 0.
C. 2 1 2.5Correct answer
5 / 2 is integer division giving 2, 5 % 2 gives remainder 1, and 5.0 / 2 promotes the int operand to double giving 2.5, so the concatenation prints 2 1 2.5.
D. 2 1 2
Truncates the last result to 2, but 5.0 / 2 has a double operand and so evaluates to 2.5.
Explanation
Division and remainder on two int operands stay in integer arithmetic, so 5 / 2 truncates to 2 and 5 % 2 is 1. Promotion to double happens only for an operation that actually has a floating-point operand, so 5.0 / 2 yields 2.5 while the earlier all-int subexpressions are unaffected. Each operation's operand types are considered independently.