+ 1

Java Challenge Fault

The Answer of the following Code pretends to be 12.0: x = 5 y = x * 2 z = x / 2 + y; System.out.println(z); The Answer should be 12,5!

4th May 2019, 9:20 AM
Malebu
Malebu - avatar
4 Answers
+ 6
it depends on what data type is used, if it's a floating point data type will definitely be 12.5 else if it's an integer then it's a two way thing on how the language handles its decimal, if .5 is round up to 0 or 1, in this case it's round up to 0, that's why you get 12.0
4th May 2019, 9:24 AM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 2
Thank you that helped me alot to make progress in Java👍.
4th May 2019, 9:31 AM
Malebu
Malebu - avatar
+ 1
Are integers always rounded down?
4th May 2019, 9:26 AM
Malebu
Malebu - avatar