title: Get integer array input from user in java
body: <p>I need to get a series of integers from the user.
  The user will not be prompted to enter the numbers. The input will be of the following form:</p>
  
  <p>6</p>
  
  <p>34 12 7 4 22 15</p>
  
  <p>3</p>
  
  <p>3 6 2</p>
  
  <p>The first line signifies the number of integers in the second line.
  I first tried to read the second line as a String and broke it to integers in the code using StringTokenizer. Sine this happens in my program a lot, it was time consuming and 
  I needed to read them directly.
  I remember in C++ it used to be fairly simple. The following code segment used to do the trick.</p>
  
  <pre><code>for(i=0;i&lt;6;i++)
  cin&gt;&gt;a[i];
  </code></pre>
  
  <p>To achieve this, I used the java.util.Scanner and my code looks as below:</p>
  
  <pre><code>InputStreamReader isr = new InputStreamReader(System.in);
  BufferedReader br = new BufferedReader(isr);
  Scanner src = new Scanner(System.in);
  
  for(x=0;x&lt;2;x++){
      arraySize = Integer.parseInt(br.readLine());
  
      for(i=0;i&lt;arraySize;i++)
          array[i] = src.nextInt();
  }
  </code></pre>
  
  <p>In this case, I am getting the following error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NumberFormatException: For input string: "34 12 7 4 22 15"
  </code></pre>
  
  <p>I am open to suggestions and am not sticking to Scanner alone. If there is any other method to achieve this, I am game.</p>