I found a error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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.

5th Aug 2020, 2:06 AM
Nightmare
Nightmare - avatar
3 Answers
+ 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...
5th Aug 2020, 2:30 AM
Sandra Meyer
Sandra Meyer - avatar
+ 3
Was just about both assignments in one line, because this will not work 😉
5th Aug 2020, 2:56 AM
Sandra Meyer
Sandra Meyer - avatar
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
5th Aug 2020, 3:02 AM
Pranav Pandey
Pranav Pandey - avatar