Code example for Scanner

Methods: hasNextIntnextInt

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