go to previous page   go to home page   go to next page

Answer:

Either order is correct.

Neither is more specific than the other, so they can appear in either order.


Possibly Incorrect Program

Here is a possibly incorrect program:

import java.util.* ;

public class DivisionPractice
{
  public static void main ( String[] a ) 
  {
    Scanner scan = new Scanner( System.in  );
    int num=0, div=0 ;

    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 (InputMismatchException ex )
     { 
      System.out.println("You entered bad data." );
      System.out.println("Run the program again." );
     }
     catch (ArithmeticException ex )
     { 
      System.out.println("You can't divide " + num + " by " + div);
     } 
  }
}

QUESTION 12:

Is the program correct? Are the catch blocks in a correct order?


go to previous page   go to home page   go to next page