title: Java exception error for input string
body: <p>I am a beginner in Java programming. I am trying to write a simple program to take size of input followed by list of numbers separated by spaces to compute the sum.</p>
  
  <p>The first input is getting in fine for the second one system shows error as it is trying to parse a blank string into integer. Can you please help with the mistake I am making?</p>
  
  <pre><code>import java.util.Scanner;
  public class InputStringforarray {
      public static void main(String[] args) {
          Scanner scan = new Scanner(System.in);
          System.out.print(" Enter size of input ");
          int num = scan.nextInt();
          System.out.println("Enter data separated by spaces: ");
          String line = scan.nextLine();
          String[] str = line.split(" ");
          int[] A = new int[num];
           int sum = 0; 
          for (int i = 0; i &lt; num; i++)
               A[i] =Integer.parseInt(str[i]); 
          for (int i = 0; i &lt; num; i++)
               sum = sum + A[i]; 
           System.out.println("Sum is " + sum);
  
  }
  
  }
  </code></pre>