Line 15
The last six lines are called a stack trace. Later you will see how to print them without stopping the program. Here is a section of the program:
try { System.out.print("Enter the numerator: "); num = scan.nextInt(); System.out.print("Enter the divisor : "); div = scan.nextInt(); System.out.println( num + " / " + div + " is " + (num/div) + " rem " + (num%div) ); } catch (ArithmeticException ex ) { System.out.println("You can't divide " + num + " by " + div); } finally { System.out.println("The program is now ending." ); } System.out.println("Good-by" );
Here are some further examples:
Example 1:
Enter the numerator: 26 Enter the divisor : 4 26 / 4 is 6 rem 2 The program is now ending. Good-by
Example 2:
Enter the numerator: 26 Enter the divisor : 0 You can't divide 26 by 0 The program is now ending. Good-by
Example 3:
Enter the numerator: 26 Enter the divisor : Zero The program is now ending. Exception in thread "main" java.util.InputMismatchExceptio at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at FinallyPractice.main(FinallyPractice.java:15)