import java.io.*; class goofy2 { public static void main (String [] args) { InputStreamReader nab = new InputStreamReader(System.in); BufferedReader grab = new BufferedReader(nab); int badness = 3; // to allow for a certain number of failed attempts int x = 2, y = 0, z; boolean messedUp = true, dire = false; System.out.println("Please enter an integer."); while ( !dire && messedUp && badness > 0 ) { try { y = Integer.parseInt(grab.readLine()); System.out.println("Thanks for entering the number " + y); messedUp = false; } catch (NumberFormatException e) { System.out.println("Sorry, that didn't make any sense!"); badness = badness - 1; if (badness > 0) System.out.println("Please try to enter an integer."); else System.out.println("Sorry, perhaps you need more coffee -- bye-bye!"); } catch (IOException e) { System.out.println("Sorry, I can't read things today!"); dire = true; } } if (dire || badness == 0) System.exit(1); z = x + y; System.out.println("The answer to "+x+" + "+y+" is = " + z); } }