Integer Division and Type Casting
What is printed when the following code segment is executed?
int x = 7;
int y = 3;
double ratio1 = x / y;
double ratio2 = (double) x / y;
double ratio3 = x / (double) y;
boolean same12 = (ratio1 == ratio2);
boolean same23 = (ratio2 == ratio3);
System.out.println(same12);
System.out.println(same23);
A
true
true
B
false
false
C
true
false
D
false
true
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 1 | 1 | 0m 00s | 100 |
| #2 | lsj08030922 | 1 | 1 | 0m 23s | 77 |
| #3 | theofanusmischa | 1 | 1 | 1m 11s | 29 |
| #4 | chunxiangxu.cxu | 1 | 1 | 1m 21s | 19 |
| #5 | bommasam000 | 1 | 2 | 2m 40s | -70 |
| #6 | liuwilliam072410 | 1 | 1 | 3m 36s | -116 |
| #7 | y.seong2027 | 2 | 4 | 5m 11s | -131 |
| #8 | zgj07310417 | 1 | 2 | 5m 31s | -241 |
| #9 | richa.tuli | 1 | 2 | 8m 49s | -439 |
Items per page:
10
1 – 9 of 9
APFIVE