title: How to read a number and a sentence using Java Scanner
body: <p>I want to understand why using Scanner.nextInt() to read a number and then using Scanner.nextLine() to read a sentence does not work as expected. I have the following code where I input a number but it skips listening to the sentence and my program terminates. Could someone explain why this is and what are alternate solutions?</p>
  <pre><code>    Scanner scanner = new Scanner(System.in);
      System.out.println(&quot;Enter a number: &quot;);
      int x = scanner.nextInt();
      System.out.println(&quot;Enter a sentence&quot;);
      System.out.println(x);
      String line = scanner.nextLine();
      System.out.println(line);
  </code></pre>