title: try-catch that will catch if user input is incorrect
body: <p>I am wondering how to do it in a way so that the user can both opt out of entering integers, and so that if the user does not enter an integer, it will catch it and re-prompt them without ending the program. I need the scanner to take in both int and string types. Is there a way to do this? Or a way around it?</p>
  
  <pre><code>/* The following method asks a user to input a series of integers. 
   * The user can stop at any time buy entering "quit"
  */
  
  public static void readSeries()
  { 
      int integer;
      Scanner scan = new Scanner(System.in);
  
      System.out.println("Please enter a series of integers. If you wish to stop, enter 'quit'. ");
      System.out.println();
  
  try{
      while(true) 
      {
          System.out.println("Enter an integer: "); // asks user to enter an integer
          integer = scan.nextInt();
  
          if(scan.equals (0)){break;}             // allows user to stop entering numbers 
      }       
  
      } catch(NumberFormatException nfe){System.out.println("Invalid Entry!");}
  
  }
  }
  </code></pre>