int a = 9;
int b = 4;
double r = (double) a / b;
System.out.println(r);What is printed?
- A
2
- B
2.0
- Ccheck_circle
2.25
- D
2.5
Explanation
Casting a to double before division forces double division, so 9.0 / 4 = 2.25.
AP Computer Science A· difficulty 3/5
int a = 9;
int b = 4;
double r = (double) a / b;
System.out.println(r);What is printed?
2
2.0
2.25
2.5
Explanation
Casting a to double before division forces double division, so 9.0 / 4 = 2.25.
Want 10 more like this — adaptive to your weak spots?