Java Reference
In-Depth Information
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();
//Line 9
quotient = dividend / divisor;
//Line 10
System.out.println("Line 11: Quotient = "
+ quotient);
//Line 11
}
catch (ArithmeticException aeRef)
//Line 12
{
System.out.println("Line 13: Exception "
+ aeRef.toString());
//Line 13
}
catch (InputMismatchException imeRef)
//Line 14
{
System.out.println("Line 15: Exception "
+ imeRef.toString()); //Line 15
}
}
}
Sample Run: (In these sample runs, the user input is shaded.)
Sample Run 1:
Line 4: Enter the dividend: 45
Line 7: Enter the divisor: 2
1
1
Line 11: Quotient = 22
Sample Run 2:
Line 4: Enter the dividend: 18
Line 7: Enter the divisor: 0
Line 13: Exception java.lang.ArithmeticException: / by zero
Sample Run 3:
Line 4: Enter the dividend: 2753
Line 7: Enter the divisor: 2f1
Line 15: Exception java.util.InputMismatchException
Search WWH ::




Custom Search