title: "exception in thread main java.lang.arrayindexoutofboundsexception" when using an array + for loop
body: <p>when I wrote this code to prompt the user for how many numbers are going to be entered, I got an error saying: "exception in thread main java.lang.arrayindexoutofboundsexception"</p>
  
  <p>PS: note that I used an array of int + for loop to write it.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import java.util.*;
  public class Pr8{
    public static void main(String[] args){
      Scanner scan = new Scanner (System.in);
      
      //Prompt the user for how many numbers are going to be entered.
      
      System.out.print("*Please write how many numbers are going to be entered: ");
      int a = scan.nextInt();
      int[] n = new int[a];
      
      for (int i = 0; i &lt; a; i++){
        System.out.print("*Please enter an enteger: ");
        n[a] = scan.nextInt();
      }//for
      
    }//main
  }//Pr8</code></pre>
  </div>
  </div>
  </p>