title: How to get out of while loop in java with Scanner method "hasNext" as condition?
body: <p>I am a beginner at java programming and has run into a strange issue. Below is my code, which asks user for input and prints out what the user inputs one word at a time.</p>
  
  <p>The problem is the program never ends, and from my limited understanding, it seem to have stuck inside the while loop. Could anyone help me a little? Thanks in advance.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Test{
     public static void main(String args[]){
        System.out.print("Enter your sentence: ");
        Scanner sc = new Scanner (System.in);
  
        while (sc.hasNext() == true ) {
          String s1 = sc.next();
          System.out.println(s1);
        }
  
        System.out.println("The loop has been ended"); // This somehow never get printed.
     }
  }
  </code></pre>