Possibly Incorrect Program

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
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?