Casting Arithmetic Result
A floating-point value is truncated to an integer before being involved in a division operation with another integer.
What is printed when the following Java program is compiled and run?
public class QuestionTrace {
public static void main(String[] args) {
double val1 = 8.7;
int val2 = 3;
double result = (int) val1 / val2;
System.out.println(result);
}
}
A
2.0
B
2.6666666666666665
C
2.9
D
3.0
Question Leaderboard
Not enough data yet to show leaderboard.
