Problem

Add a try-catch structure to the following program to make it compile and execute correctl...

Add a try-catch structure to the following program to make it compile and execute correctly, even when the divisor is zero. Note that division by zero throws an ArithmeticException.

import java.util.Scanner;public class Division{public static void main(String[] args){Scanner stdIn = new Scanner(System.in);int n, d, q;System.out.print("Enter numerator: ");n = stdIn.nextInt();System.out.print("Enter divisor: ");d = stdIn.nextInt();q = n / d;System.out.println(q);} // end main} // end Division classTo help you out, we’ve provided the catch block, below:catch (ArithmeticException e){System.out.println("Error, but keep going anyway.");}

There’s no need to check for correct input; you may assume that the user enters two properly formatted int values for input.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 14
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT