Given the code snippet: int x = 5; int y = 2; double result = x / y; What is the value of result?
Trap 1: Compilation fails
Incorrect because the code compiles.
Trap 2: 2.5
Incorrect because integer division truncates.
Trap 3: 2
Incorrect because result is double, so it is 2.0 not 2.
- A
2.0
Correct because integer division yields 2, then cast to double.
- B
Compilation fails
Why wrong: Incorrect because the code compiles.
- C
2.5
Why wrong: Incorrect because integer division truncates.
- D
2
Why wrong: Incorrect because result is double, so it is 2.0 not 2.