title: Java Pause Until Any Key Pressed
body: <p>I was wondering if there is an option in Java which would allow you to pause program until any key pressed.
  This is one part of my code, eventually it is a part of a while loop in another class.</p>
  
  <pre><code>public void menu()
  {
      boolean exit = false;
  
      System.out.println("-- Command interpreter --");
      System.out.println("[1] Write results to console");
      System.out.println("[2] Write results to text file");
      System.out.println("[3] exit");
      System.out.println("-------------------------");
      System.out.print("Input Value: ");
  
      String s = scaner.nextLine();
  
      int i = Integer.parseInt(s);
  
      switch (i)
      {
          case 1:
          {
              writeToScr(listPopulation);
              System.out.println("\n\nPress any key to continue..");
              scaner.next();
              break;
          }
          case 2:
          {
              writeToFile(listPopulation);
              System.out.println("\n\nPress any key to continue..");
              scaner.next();
              break;
          }
          case 3:
          {
              exit = true;
              break;
          }
          default:
          {
              System.out.println("Unknown Entry.");
              break;
          }
      }
  
      if (exit)
      {
          System.out.println("Exit!");
          return;
      }
  }
  </code></pre>
  
  <p>So what i want to accomplish is, for example in case 1, when i get results written to console, i want for program to pause and let me check what i have until i press any key. My code works only for ENTER, or any text + ENTER. Is there a way that i could press any key without pressing ENTER afterwards and the program continues?</p>