Java - What is the output: float dividing by zero

Question

What is the output of the following code.

public class Main{

  public static void main(String[] args) {

    System.out.println(0F/0);
    System.out.println(0.1/0);
    System.out.println(-0.1F/0);
  }
}


Click to view the answer

NaN
Infinity
-Infinity

Demo

public class Main{

  public static void main(String[] args) {

    System.out.println(0F/0);/*from  www.jav  a2  s .  c  o  m*/
    System.out.println(0.1/0);
    System.out.println(-0.1F/0);
  }
}

Note

Infinity has positive and negative.

Related Quiz