import java.util.Scanner; public class ExceptionTestProgram4 { public static void main(String[] args) { int number1 = 0, number2 = 0, result = 0; boolean gotANumber = false; Scanner keyboard; keyboard = new Scanner(System.in); while(!gotANumber) { try { System.out.println("Enter the first number"); number1 = keyboard.nextInt(); gotANumber = true; } catch (java.util.InputMismatchException e) { System.out.println("Invalid integer. Please re-enter"); keyboard = new Scanner(System.in); } } gotANumber = false; while(!gotANumber) { try { System.out.println("Enter the second number"); number2 = keyboard.nextInt(); gotANumber = true; } catch (java.util.InputMismatchException e) { System.out.println("Invalid integer. Please re-enter"); keyboard = new Scanner(System.in); } } try { result = number1 / number2; System.out.print(number2 + " goes into " + number1); System.out.println(" this many times: " + result); } catch (ArithmeticException e) { System.out.println("Second number is 0, cannot do division!"); } } }