import java.util.Scanner; public class IOerror { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x; //Let's make use of the "break" statement... while (true) { try { System.out.print("Enter an integer please: "); x=sc.nextInt(); break; } catch (Exception e){ System.out.println(e); sc.next(); } } System.out.println("Yay, you typed an integer!"); } } //Copyright 2010-2012 : Evan Golub