Question:
Why does 1.0/0.0 not throw a java.lang.ArithmeticException: / by zero?
Answer:
Floating point data types have a special value reserved to represent infinity, integer values do not.
The code 1/0 is an integer division fails. However, 1/0.0 is a floating point division and so results in Infinity.
The code 1/0 is an integer division fails. However, 1/0.0 is a floating point division and so results in Infinity.
Code:
public class Example { public static void main(String args[]){ System.out.println("1.0 / 0.0 == " + 1.0/0.0); } }
Output:
$ java Example 1.0 / 0.0 == Infinity