title: How to read the user inputs(including spaces) line by line with Scanner?
body: <p>I need to read user inputs line by line (may be included spaces). I had already read <a href="https://stackoverflow.com/questions/19509647/scanner-doesnt-see-after-space-java">Scanner doesn't see after space</a> question. So I used with <code>scanner.nextLine()</code> but this method does not help my program. Below is my sample program ....</p>
  
  <pre><code>public class TestingScanner {
      public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      System.out.println("How many friends do you have ?");
      int size = sc.nextInt();
      String[] names = new String[size];
      for (int i = 0; i &lt; size; i++) {
          System.out.println("Enter your name of friend" + (i + 1));
          names[i] = sc.nextLine();
      }
      System.out.println("*****************************");
      System.out.println("Your friends are : ");
      for (int i = 0; i &lt; names.length; i++) {
          System.out.println(names[i]);
      }
      System.out.println("*****************************");
      }
  }
  </code></pre>
  
  <p>While runnig my program , after inserted no: of friend , my program produces two lines as below. How can I solve it ? Thanks.</p>
  
  <p><a href="https://i.stack.imgur.com/hIoWj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hIoWj.png" alt="enter image description here"></a></p>