Code example for Scanner

Methods: hasNextIntnextInt

  private static String indent = "";  // indentation for trace 
  public static void main(String[] args)
    Scanner conIn = new Scanner(;
    // Number of rings on starting peg. 
    int n;       
    System.out.print("Input the number of rings: ");
    if (conIn.hasNextInt())
      n = conIn.nextInt();
      System.out.println("Error: you must enter an integer.");
      System.out.println("Terminating program.");
    System.out.println("Towers of Hanoi with " + n + " rings\n");
Connect your IDE to all the code out there  Get Codota for Java