title: Setting up Looping Menu in Java with I/O
body: <p>I've been having an issue trying to setup a simple menu in Java with an output to a file. When I run this program with the menu choice "1." I get the output seen in the link. <a href="https://i.stack.imgur.com/8Onpw.png" rel="nofollow noreferrer">Output</a></p>
  
  <pre><code>public static void main(String args[])
            throws FileNotFoundException{
              PrintStream output = new PrintStream( new File("hello.txt")); // created 
              Scanner keyboard = new Scanner(System.in);
  
              System.out.println("1. favorite pie");
              System.out.println("2. favorite tv show");
              System.out.println("3. favorite number");
              System.out.println("Enter your choice: ");
  
              int selection = keyboard.nextInt(); // is javadoc comment precondiiton sufficient here?
  
  
  
               while (!keyboard.hasNextInt()){
                  System.out.println("Input an integer"); 
                  selection = keyboard.nextInt(); //if user puts in double will an error be thrown?
              }
  
  
              if (selection ==1){
                  System.out.println("What is your favorite pie?");
                  String favoriteFood = keyboard.nextLine();
                  System.out.println("Your favorite pie is" + favoriteFood);
                  output.println(favoriteFood);
              }
              else if(selection ==2){
                  System.out.println("What is your favorite tv show?");
                  String tvFood = keyboard.nextLine();
                  System.out.println(tvFood);
                  output.println(tvFood);
              }
              else if (selection == 3){
                  System.out.println("what is your favorite number?");
                  String num = keyboard.nextLine();
                  System.out.println(num);
                  output.println(num);
              }
        }
  </code></pre>