title: Trying to figure out how to take enter key as user input to signal printMenu()
body: <p>I have written the following application, everything is working properly. However after the user inputs a value (1-7) that corresponds to a menu command, the command is performed and then the program terminates. I am trying to find a way that allows me to ask the user to &quot;press enter&quot; after the results of a command are displayed, to re-print the menu and continue entering commands until they are ready to exit(8). Meaning pressing enter would re-print the menu and allow more commands(1-8) to be entered.  I know this needs to be done as a loop but I am unsure of which/how to use the loop in this situation. Thank You.</p>
  <pre class="lang-java prettyprint-override"><code>import java.util.*;
  import java.io.*;
  
  public class RosterApplication {
  
      Scanner in = null;
  
      public static void main(String[] args) {
          Roster studentRoster = new Roster();
          studentRoster.loadData(&quot;assg3_roster.txt&quot;);
  
          printMenu();
  
          Scanner keyboard = new Scanner(System.in);
          String entry = keyboard.next();
  
          if (entry.equals(&quot;1&quot;)) { //Display the roster
              studentRoster.displayRoster();
          }
          //System.out.println(&quot;Press enter to continue:&quot;);
          //String reload = keyboard.nextLine();
          //if (reload.equals(&quot;&quot;)) {
          //  printMenu();
          //}
          if (entry.equals(&quot;2&quot;)) { //Search for a student by id
              System.out.println(&quot;Please enter the student id to search: &quot;);
              String searchId = keyboard.next();
              if ((studentRoster.searchForStudent(searchId)) == null) {
                  System.out.println(&quot;Student not found!&quot;);
              }
  
          }
          if (entry.equals(&quot;3&quot;)) { //Add a new student
              System.out.println(&quot;Please enter the student id to add: &quot;);
              String addId = keyboard.next();
              if (studentRoster.searchForStudent(addId) != null) {
                  System.out.println(&quot;Error: This student already exists! Student's info displayed above.&quot; + &quot;\n&quot;);
              } else {
                  System.out.println(&quot;Please enter the student name: &quot;);
                  String addName = keyboard.next() + &quot; &quot; + keyboard.next();
                  System.out.println(&quot;Please enter the student standing: &quot;);
                  String addStanding = keyboard.next();
                  System.out.println(&quot;Please enter the student major: &quot;);
                  String addMajor = keyboard.next();
                  studentRoster.addStudent(addId, addName, addStanding, addMajor);
                  System.out.println(&quot;The entered information has succesfully been added as a new student.&quot; + &quot;\n&quot;);
              }
  
          }
          if (entry.equals(&quot;4&quot;)) { //Remove a student
              System.out.println(&quot;Please enter the student id to remove: &quot;);
              String removeId = keyboard.next();
              studentRoster.removeStudent(removeId);
          }
          if (entry.equals(&quot;5&quot;)) { //Search for student by major
              System.out.println(&quot;Please enter the major to search: &quot;);
              String majorSearch = keyboard.next();
              ArrayList &lt; Student &gt; students = studentRoster.getStudentByMajor(majorSearch);
              if (students.size() != 0) {
                  System.out.println(&quot;The students with this major are listed above.&quot;);
              } else {
                  System.out.println(&quot;Error: There are no students with this major!&quot;);
              }
          }
          if (entry.equals(&quot;6&quot;)) { //Sort and save to file
              studentRoster.Sort();
              studentRoster.Save();
          }
          if (entry.equals(&quot;7&quot;)) { //Save to file
              studentRoster.Save();
          }
          if (entry.equals(&quot;8&quot;)) { //Exit
              studentRoster.Save();
              System.exit(0);
          }
          
          keyboard.close();
      }
  
      private static void printMenu() {
          System.out.println(&quot;1. Display the roster&quot;);
          System.out.println(&quot;2. Search for a student by id&quot;);
          System.out.println(&quot;3. Add a new student&quot;);
          System.out.println(&quot;4. Remove a student&quot;);
          System.out.println(&quot;5. Search for students by major&quot;);
          System.out.println(&quot;6. Sort and save to file&quot;);
          System.out.println(&quot;7. Save to file&quot;);
          System.out.println(&quot;8. Exit&quot;);
      }
  }
  </code></pre>