Add a
try-catchstructure 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
catchblock, 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
intvalues for input.
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.