title: Java - How to read integers separated by a space into an array
body: <p>I am having trouble with my project because I can't get the beginning correct, which is to read a line of integers separated by a space from the user and place the values into an array.</p>
  
  <pre><code>    System.out.println("Enter the elements separated by spaces: ");
      String input = sc.next();
      StringTokenizer strToken = new StringTokenizer(input);
      int count = strToken.countTokens();
      //Reads in the numbers to the array
      System.out.println("Count: " + count);
      int[] arr = new int[count];
  
      for(int x = 0;x &lt; count;x++){
          arr[x] = Integer.parseInt((String)strToken.nextElement());
      }
  </code></pre>
  
  <p>This is what I have, and it only seems to read the first element in the array because when count is initialized, it is set to 1 for some reason.</p>
  
  <p>Can anyone help me? Would it be better to do this a different way?</p>