Home » JAVA Programming » Basic Datatypes » Question
  1. What will be the output of these statement?

    class output {
    public static void main(String args[])
    {
    double p, q, r;
    p = 3.0/0;
    q = 0/4.0;
    r = 0/0.0;

    System.out.println(p);
    System.out.println(q);
    System.out.println(r);
    }
    }
    1. 0.0
    2. Infinity
    3. NaN
    4. all of the mentioned
    5. None of these
Correct Option: D

For floating point literals, we have constant value to represent (10/0.0) infinity either positive or negative and also have NaN (not a number for undefined like 0/0.0), but for the integral type, we don’t have any constant that’s why we get an arithmetic exception.



Your comments will be displayed only after manual approval.