+ 1

Where is the error?

It interesting... One of exercise is wrong What is the result of the following code? int x = 15; int y = 4; int result = x / y; System.out.println(result); For answer is only place for one number. Answer is 3,75, but I can't write it. I used hint..Answer is 3!!! Please change x.. or answer.. Really interesting... :D

2nd Sep 2018, 4:55 PM
Grzegorz Janik
Grzegorz Janik - avatar
2 Respuestas
+ 7
welcome to programming! in this world 15/4 = 3 (integer division) 15.0/4.0 or 15/4.0 or 15.0/4 equals 3.75
2nd Sep 2018, 5:09 PM
code learner
code learner - avatar
+ 3
The answer is 3 because int format is only for whole numbers. For example if x, y and result were declared as double then your answer is right 3.75.
2nd Sep 2018, 5:09 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar