Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Dive into the depths of Java with our quiz based on "Thinking in Java, Fourth Edition" by Bruce Eckel. Test your knowledge, solidify concepts, and prepare for certification with challenging questions and insightful feedback.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


What will happen if you attempt to divide by zero using floating-point numbers in Java?

  1. Compiler error

  2. ArithmeticException is thrown

  3. Results in NaN for floating-point division

  4. Results in Infinity or -Infinity depending on the sign

The correct answer is: Results in Infinity or -Infinity depending on the sign

When attempting to divide by zero using floating-point numbers, Java will result in either positive or negative infinity depending on the sign of the dividend. This is because division by zero is undefined in mathematics and can result in an infinite value. Option A is incorrect because a compiler error will not occur. Option B is incorrect because an ArithmeticException will not be thrown for this scenario. Option C is incorrect because NaN, or "not a number," is only the result when dividing by zero using floating-point numbers when the dividend is also zero.