ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
System.out.print(5.0 / 0 + " ");
System.out.print(0.0 / 0 + " ");
try { System.out.print(5 / 0); }
catch (ArithmeticException e) { System.out.print("AE"); }
  1. A. AE AE AE
  2. B. Infinity NaN AE
  3. C. Infinity NaN Infinity
  4. D. Infinity 0 AE

Correct answer: B. Infinity NaN AE

Floating-point division follows IEEE 754: 5.0 / 0 is Infinity and 0.0 / 0 is NaN, with no exception. Integer division by zero throws ArithmeticException.

More OOP with C++ and Java questions

Exams that ask this topic