/**
 * Exercise 12.2 from the book Introduction to Java Programming (10th).
 * <p>
 * InputMismatchException
 * <p>
 * Sums two given integers. An exception will be thrown if the user does
 * not enter integers. This exception is caught and the user is again instructed
 * to enter integers.
 */

import java.util.Scanner;

public class Exercise_12_02 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

		boolean done = false;
		int number1 = 0;
		int number2 = 0;

		System.out.print("Enter two integers: ");

		while (!done) {
			try {
				number1 = input.nextInt();
				number2 = input.nextInt();
				done = true;
			} catch (Exception ex) {
				ex.printStackTrace();
				System.out.print("Incorrect input and re-enter two integers: ");
				input.nextLine(); // Discard input
			}
		}

		System.out.println("Sum is " + (number1 + number2));
	}
}

@@ -720,16 +720,18 @@
 ut.print
+ln
 (%22Incorr
@@ -744,16 +744,52 @@
 put 
-and re-e
+please try again.%22);%0A%09%09%09%09System.out.print(%22E
 nter

Update Exercise_12_02.java