divide by zero in Java

You might be thinking,  divide by zero will throw ArithmeticException. But this is not true for floating point numbers.

Divide by zero throws ArithmeticException only when char or integral value are divided by 0. Below two operation throws exception

10/0
'A'/0

If floating point number is divided by 0, output will be Infinity.

10.2/0
-10.3/0

Output:
Infinity
-Infinity


Comments

Post a Comment

Popular posts from this blog

Data types and Literals in Java

equals() method of Object class in Java

Create your own LinkedList in Java