Handling an ArithmeticException. The following program calls getQuotient, which divides its two passed-in values and returns the
Question:
Handling an ArithmeticException.
The following program calls getQuotient, which divides its two passed-in values and returns the quotient as a floating-point number.
The program works well for the normal cases, but when the user enters 0 for the divisor, the program generates this error:
Exception in thread "main" java.lang.ArithmeticException: / by zero Modify the getQuotient method by putting the division operation in a try block and following it with a catch block that returns either Double.POSTIVE_INFINITY if the dividend is positive or Double.NEGATIVE_INFINITY if the dividend is negative.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Related Book For
Introduction To Programming With Java A Problem Solving Approach
ISBN: 9781260575248
3rd International Edition
Authors: John Dean
Question Posted: