0 votes
243 views
in JAVA by (98.9k points)
edited

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

1 Answer

0 votes
by (98.9k points)
selected by
 
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.

Related questions

0 votes
1 answer 153 views
asked Jul 20, 2022 in JAVA by Doubtly (98.9k points)
0 votes
1 answer 156 views
asked Jul 20, 2022 in JAVA by Doubtly (98.9k points)
0 votes
1 answer 98 views
asked Jul 20, 2022 in JAVA by Doubtly (98.9k points)
0 votes
0 answers 114 views
asked Aug 9, 2022 in JAVA by Doubtly (98.9k points)

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

557 users

...