// ExceptionTest.java // Test exception handling in Java import java.util.*; public class ExceptionTest { public static void main(String[] args) { Scanner in = new Scanner(System.in); int num = 0; boolean gotNumber = false; while (!gotNumber) { try { System.out.print("Enter an integer: "); num = in.nextInt(); gotNumber = true; } catch (InputMismatchException e) { System.err.println("Error: not an integer"); //System.err.println("Error: " + e); in.next(); // skip non-integer input } } System.out.println("You entered " + num); } }