Skip to content
doubtly

What will be the output of the following Java program? a) NaN b) Infinity c) 0.0 d) all of the mentioned

What will be the output of the following Java program?

  1. class output {
  2.         public static void main(String args[]) 
  3.         {
  4.             double a, b,c;
  5.             a = 3.0/0;
  6.             b = 0/4.0;
  7.             c=0/0.0;
  8.  
  9. 	    System.out.println(a);
  10.             System.out.println(b);
  11.             System.out.println(c);
  12.         } 
  13.     }

a) NaN
b) Infinity
c) 0.0
d) all of the mentioned

Doubtly Asked Student doubt Save WhatsApp Report

1 answer

Best answer

Answer: d
Explanation: 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.
Doubtly · 20 Jul 2022 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.