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.

import java.util.Scanner; public class Division ByZero { public static void main(String[] args) { Scanner

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:

Question Posted: