title: Take a single line input of numbers, and storing it into an array
body: <pre><code>import java.util.Scanner;
  
  class HistogramChart
  {
     public static void main(String[] args)
     {
        Scanner scan = new Scanner(System.in);
  
        System.out.println("Please enter the population of data: ");
        int populationOfData = scan.nextInt();
  
        System.out.println("Please enter data separated by spaces: ");
        String data = scan.next();
  
        int indexWhiteSpace = data.indexOf(" ");
  
        int[] dataArray = new int[populationOfData];
        int tempInt = 0;
  
        for(int index = 0; index &lt; populationOfData; index++)
        {
           String tempString = data.substring(0, indexWhiteSpace);
           data = data.substring(indexWhiteSpace+1, data.length());
           tempInt = Integer.parseInt(tempString);
  
           dataArray[index] = tempInt;
           indexWhiteSpace = data.indexOf(" ");
        }
        System.out.println(dataArray[0]);   
     }
  }
  </code></pre>
  
  <p>I realize there's nothing yet to print out the entire array, as i'm just trying to get it to print anything, but this is continually printing the following errors:</p>
  
  <p>"Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
      at java.lang.String.substring(String.java:1954)
      at HistogramChart.main(HistogramChart.java:22)
  "
  I cannot figure out why this is saying this. 
  Please help!</p>