ExceptionExample5

ExceptionExample5 - //Line 9 quotient = dividend / divisor;...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.*; i public class ExceptionExample5 { static Scanner console = new Scanner(System.in); public static void main(String[] args) //Line 1 { int dividend, divisor, quotient; //Line 2 try //Line 3 { System.out.print("Line 4: Enter the " + "dividend: "); //Line 4 dividend = console.nextInt(); //Line 5 System.out.println(); //Line 6 System.out.print("Line 7: Enter the " + "divisor: "); //Line 7 divisor = console.nextInt(); //Line 8 System.out.println();
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //Line 9 quotient = dividend / divisor; //Line 10 System.out.println("Line 11: Quotient = " + quotient); //Line 11 } catch (Exception eRef) //Line 12 { if (eRef instanceof ArithmeticException) //Line 13 System.out.println("Line 14: Exception " + eRef.toString()); //Line 14 else if (eRef instanceof InputMismatchException) //Line 15 System.out.println("Line 16: Exception " + eRef.toString()); //Line 16 } } }...
View Full Document

This note was uploaded on 06/17/2011 for the course COMP 2301 taught by Professor Staff during the Spring '10 term at Kennesaw.

Ask a homework question - tutors are online