-1

Why is it that division of an integer by 0 gives ArithmeticException whereas division of a non-zero double or float by 0,prints Infinity. Also division of an int 0 by 0 gives ArithmeticException whereas division of a double or float 0 by 0 gives NaN(Not a number).

public class First
{
    public static void main(String[] args)
    {
        System.out.println(10/0); //Arithmetic Exception
        System.out.println(10.0/0); //Prints Infinity

    }
}
Frosted Cupcake
  • 1,909
  • 2
  • 20
  • 42

2 Answers2

1

java follows IEEE floating point standards/practices, and those incorporate infinity [+ and -] as a value that can be calculated with, and NaN as a representation for results that are not a number.

(And obviously, those floating point standards do not have a counterpart for integer arithmetic.)

Erwin Smout
  • 18,113
  • 4
  • 33
  • 52
1

Division by a floating point 0.0 yields NaN or +/-Inf.

Division by an integer 0 is not covered by IEEE 754, and generates an exception - (i.e because an int can't represent NaN or Inf).

Mammadreza
  • 84
  • 8