title: ArrayIndexOutOfBoundsException: 100, Beginner Project
body: <p>So im working on this project for class and I am to read a text file called "randomNumbers" store it in an array and print it out to the screen. It complies fine but when I run the code I get</p>
  
  <pre><code>enter code here
  Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100
  at projectFour.read_file(projectFour.java:32)
  at projectFour.main(projectFour.java:13)
  </code></pre>
  
  <p>Iv tried to the best of my ability to solve it but I am stuck. </p>
  
  <p>Here is the code I have thus far, </p>
  
  <pre><code>enter code here import java.io.File;
  import java.util.Scanner;
  import java.io.BufferedWriter;
  import java.io.FileWriter;
  import java.io.IOException;
  
  public class projectFour
  {
  public static int [] global_numbers;
  
  
  public static void main (String[] args)
  {
    read_file();
    print_numbers(global_numbers);
  
  }
  
  
  
  public static void read_file()
  {
  try
        {
          File file = new File("randomNumbers.txt"); 
          Scanner scan = new Scanner(file);
          int maxNumberInFile = convertingStringToInt(scan.nextLine()); // read the first line which is 100 to set array size
          global_numbers = new int[maxNumberInFile]; // set the array size equal to the first line read which is 100
          int i = 0; 
  
               while(scan.hasNextLine()) // while there is a next line to read, do this...
                {
                   String line = scan.nextLine();
                   global_numbers [i] = convertingStringToInt(line); 
                   i++; 
                }
                   scan.close();        
        }
  
    catch(IOException ex)
          {
             ex.printStackTrace();
          }    
  
  }
  
  public static int convertingStringToInt(String number)
  {  
  try
       {
          return Integer.parseInt(number);
       }
  
    catch(NumberFormatException n)
       {
             return -460;
       }         
  }
  
  public static void print_numbers(int [] numbers)
  {
    int max = numbers.length;
    for(int i = 0; i &lt; max; i++)
       {
          System.out.println(numbers[i]); 
       }
  }
  }
  </code></pre>