+ 2

Division by zero (Java)

What is the output of this code? double d = 33.44 / 0.0; System.out.println(d);

5th Jul 2019, 12:36 PM
Panos
Panos - avatar
2 ответов
+ 3
If d was int, Java would throw an ArithmeticException. But here, d is float so division by zero returns Infinity.
5th Jul 2019, 3:40 PM
Ilias Chrysopoulos
Ilias Chrysopoulos - avatar
+ 5
Try it yourself, in Java Editor, in sololearn
5th Jul 2019, 12:38 PM
Sarthak Pokhrel
Sarthak Pokhrel - avatar