title: Can someone help me understand why I need an IF and WHILE for this answer?
body: <p>Quick question- I have found the correct answer to this quiz question but I don't fully understand it.</p>
  
  <p><strong>here is the question-</strong></p>
  
  <p>Given a Scanner reference variable named input that has been associated with an input source consisting of a sequence of lines, write the code necessary to read in every line and print them all out on a single line, separated by a space. </p>
  
  <p><strong>here is the answer-</strong></p>
  
  <pre><code>if(input.hasNext())
      System.out.print(input.nextLine());
      while (input.hasNext()){
          System.out.print(" " + input.nextLine());
      }
  }
  </code></pre>
  
  <p><strong>My question is</strong>, why does there need to be an if and while statement. I understand I need to first read in the line and then print it out. Why wouldn't it be sufficient to have just :</p>
  
  <pre><code>while(input.hasNext()){
      System.out.print(" " + input.nextLine());
  }
  </code></pre>
  
  <p>Thank you</p>