title: Read a multi-word string from stdin
body: <p>I want to read multiple words into a string called <code>input</code>. The words can be casted into numeric values like <code>"1 14 5 9 13"</code>. After the user input, the string will be converted into a string array separated by spaces.</p>
  
  <pre><code>public class ArraySum {
  
    public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      int n = Integer.parseInt(scanner.next());
      System.out.println("Please enter "+n+" numbers");
      String input = scanner.next(); // ERROR: only the first word is read
      String[] inputs  = input.split("\\s+"); 
      int sum=0;
      for (int i =0; i&lt;inputs.length; i++){
          if (!inputs[i].equals(""))
              sum+= Long.parseLong(inputs[i]);
      }
      System.out.print(sum);
  }
  }
  </code></pre>
  
  <p>However only the first word is read into the string.</p>
  
  <p><a href="https://stackoverflow.com/a/20141323/5531761">This answer</a> suggests using <code>nextLine()</code> to read a multi-word string, but if I change it, an error was thrown. </p>
  
  <blockquote>
    <p>java.lang.NumberFormatException: null</p>
  </blockquote>
  
  <p>Apparently an empty/null string was inputted before I entered any word.</p>