import java.util.*; // for Scanner public class Exception2 // simple example to demonstrate the use of try and multiple catch blocks { public static void main(String[] args) { int[] array=new int[5]; // if we aren't careful, we could get an ArrayIndexOutOfBoundsException int number=0, z=0; // z is a divisor input by the user, it could generate an ArithmeticException if we divide by 0 Scanner s=new Scanner(System.in); // could generate an InputMismatchException do { // the loop is used to iterate over inputs from the user of array values and a divisor try{ // until the user enters -9999 for a divisor System.out.print("Enter next number: "); array[number]=s.nextInt(); // can cause an InputMismatchException or ArrayIndexOutOfBoundsException System.out.print("Enter a divisor, -9999 when done: "); z=s.nextInt(); // can cause an InputMismatchException array[number]=array[number]/z; // can cause an ArithmeticException (divide by 0) number++; } catch(ArithmeticException e) { System.out.println(e); } catch(ArrayIndexOutOfBoundsException e) { System.out.println(e); // if we have reached the limit of the array, force the loop to terminate z=-9999; } catch(InputMismatchException e) { System.out.println(e); } }while(z!=-9999); for(int i=0;i