Also, if no input is given then it should System.exit().
Here is my attempt that will catch a non integer input and print "Error" but it wont as for number of disks again.
try { System.out.print("\nHow many disks should we use for Hanoi problem: "); input = keyboard.nextLine(); n = Integer.valueOf(input); } catch (NumberFormatException nfe) { System.out.println("Error: Invalid Input."); } int userInput = keyboard.nextInt(); while (userInput <= 0) { System.out.print("Invalid! Input must be greater than 0."); }