title: Get different types of input in Java
body: <p>I'm fairly new to Java and programming in general, I'm working on a program which is supposed to get input from user and based on that create/delete class instances.</p>
  
  <p>Here is the code: </p>
  
  <pre><code>while(true) {
      int is = -1; //0 is the number of first istance
      try(Scanner s = new Scanner(System.in);){
          System.out.print("Enter the desired action: ");
          String input = s.next();
          if(input.equals("j")){
              (new Thread(new Parser())).start();
          }
  
          is = Integer.parseInt(input);
  
          if (is &gt;= 0 &amp;&amp; is &lt;= (Parser.count - 1)) {
              Parser.kill(is);    
          }else {
              System.out.println("wrong key");
              break;
          }
      }catch(NumberFormatException e){
          System.out.println("exception");// 
      }
  }
  </code></pre>
  
  <p>The main issue is that it throws "NoSuchElementException" if the input is not "j", I tried to catch the exception, but in that case the program goes in a loop and stop waiting for user input. Here is the stack trace: </p>
  
  <pre><code>java.lang.NumberFormatException: For input string: "m"
      at java.lang.NumberFormatException.forInputString(Unknown Source)
      at java.lang.Integer.parseInt(Unknown Source)
      at java.lang.Integer.parseInt(Unknown Source)
      at Task.run(Task.java:17)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>Could you point me out to what I'm doing wrong? Is there any library that could help me making a cmd like program?</p>