class ComputeQuotient
1: //ComputeQuotient.java:Adapted from Holmes, Chapter 9
2: //Demonstrates creating an (arithmetic) exception and
3: //allowing the Java interpreter to handle it.
5: import java.io.*;
7: class ComputeQuotient
8: {
9: static BufferedReader keyboard =
10: new BufferedReader(new InputStreamReader(System.in));
11: static PrintWriter screen =
12: new PrintWriter(System.out, true);
14: public static void main(String[] args)
15: throws Exception
16: {
17: int dividend, divisor, quotient;
19: screen.print("\nEnter dividend: "); screen.flush();
20: dividend = new Integer(keyboard.readLine()).intValue();
21: screen.print("Enter divisor: "); screen.flush();
22: divisor = new Integer(keyboard.readLine()).intValue();
24: //Arithmetic exception thrown here if divisor is zero
25: quotient = dividend/divisor;
26: screen.println("Quotient = " + quotient + "\n");
27: }
28: }