title: Print Statement Replacing User Input
body: <p>I have a <code>main</code> method as well as a <code>mainMenu</code> method. My goal is to call <code>mainMenu</code> after <code>main</code> is executed. If the user input is not an integer then print that it must be and recall the <code>mainMenu</code> method.</p>
  
  <p>Here are my two methods:</p>
  
  <pre><code>private static Scanner s = new Scanner(System.in);
  public static void main(String[] args) {
      System.out.println("Welcome to Sea Bank!\n");
      try {
          TimeUnit.SECONDS.sleep(2);
      } catch(InterruptedException e) {
          Thread.currentThread().interrupt();
      }
      mainMenu();
  }
  
  public static void mainMenu() {
      System.out.println("Please select an item below:");
      System.out.println("(0) Login");
      System.out.println("(1) Create Account");
      System.out.print("&gt;&gt; ");
      try {
          int mainMenu = s.nextInt();
          if (mainMenu == 0) {
              login();
          } else if (mainMenu == 1) {
              System.out.println("coo create acc"); //add in account creation
          }
      } catch(InputMismatchException e) {
          System.out.println("\nPlease enter an integer");
          mainMenu();
      }
  }
  </code></pre>
  
  <p>So basically when I call the <code>mainMenu</code> method in <code>main</code> and enter a String instead of an int it returns a StackOverFlowError instead of re-asking for user input for an int.</p>
  
  <pre><code>    ...
      Please enter an integer
      &gt;&gt; 
      Please enter an integer
      &gt;&gt; 
      Please enter an integer
      &gt;&gt; 
      Please enter an integer
      &gt;&gt; 
      Please enter an integer
      &gt;&gt; Exception in thread "main" java.lang.StackOverflowError
          at java.util.regex.Pattern$CharProperty.match(Pattern.java:3776)
          at java.util.regex.Pattern$Branch.match(Pattern.java:4604)
          at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658)
          at java.util.regex.Pattern$Curly.match(Pattern.java:4227)
          at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658)
          at java.util.regex.Pattern$Branch.match(Pattern.java:4604)
          at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658)
          at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658)
          at java.util.regex.Pattern$Ques.match(Pattern.java:4182)
          at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658)
          at java.util.regex.Pattern$GroupHead.match(Pattern.java:4658)
          at java.util.regex.Pattern$Branch.match(Pattern.java:4604)
          at java.util.regex.Matcher.match(Matcher.java:1270)
          at java.util.regex.Matcher.matches(Matcher.java:604)
          at java.util.Scanner.getCompleteTokenInBuffer(Scanner.java:963)
          at java.util.Scanner.next(Scanner.java:1476)
          at java.util.Scanner.nextInt(Scanner.java:2117)
          at java.util.Scanner.nextInt(Scanner.java:2076)
          at main.bank.seabank.Main.mainMenu(Main.java:35)
  </code></pre>
  
  <p>I'm assuming the user input repeatedly is taking in "Please enter an integer" instead of allowing actual user input. I'm just not quite sure how to fix this.</p>