0
I found a error
So the code was this: int x = 15; int y = 4; int result = x / y; System.out.println(result);' You follow basic math evaluation: 15/4 = 3.75. However, the space would only let me type one number, and using 5 points for a hint the answer was 3. But, for this to work, int y would have to equal 5, not 4, as 15/5 = 3. Please fix this, Sololearn Devs.
6 odpowiedzi
+ 4
@swim I think the code line is broken, guess you meant
double res = (double) 15 / (double) 4;
did you? Would be confusing otherwise, if you wanted to show multiple options...
+ 3
Was just about both assignments in one line, because this will not work 😉
0
In JAVA,
The compiler does the integral division i.e. only shows the quotient discarding the remainder if both the operands are integers.
To execute real division, either one or both the operands should be a float or a double.
Examples
1) 15/4
OUTPUT
3
2) 15.0/4
OUTPUT
3.75
2) 15/4.0
OUTPUT
3.75
3) 15.0/4.0
OUTPUT
3.75