title: Read input line by line
body: <p>How do I read input line by line in Java? I searched and so far I have this:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class MatrixReader {
      public static void main(String[] args) {
          Scanner input = new Scanner(System.in);
          while (input.hasNext()) {
              System.out.print(input.nextLine());
          }
      }
  </code></pre>
  
  <p>The problem with this is that it doesn't read the last line. So if I input </p>
  
  <pre><code> 10 5 4 20
   11 6 55 3
   9 33 27 16
  </code></pre>
  
  <p>its output will only be</p>
  
  <pre><code>10 5 4 20 11 6 55 3
  </code></pre>