title: Array Index Out Of Bounds Exception
body: <p>The problem:</p>
  
  <blockquote>
    <p>a program that updates a list of students’ grades after the end of drop period. The program should reads from the user number of students who dropped and their indexes, and then the program should copies the remaining student’s grades to new array. In addition, the program should display both the original and the updated list. [Hint: the new array must have suitable length equivalents to number of remaining students]</p>
  </blockquote>
  
  <p>my code:</p>
  
  <pre><code>public class Q5{
    static Scanner scan = new Scanner (System.in);
    public static void main (String args[]){
  
      double [] list={1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10};
      System.out.println("enter number of students who dropped:");
      int num=scan.nextInt();
      double [] list2 = new double [num];
  
      System.out.println("Enter index Of  the student who dropped ");
      for (int j=1 ; j&lt;=num ; j++)
      {
        System.out.println("student" + j + ":");
        int index=scan.nextInt();
        list[index]=0;
      }
  
      int  j=0;
      for(int i=0; i&lt;list.length ; i++)
      if (list[i]!=0)
      {
        list2[j]=list[i];
        j++;
      }
      System.out.print("The original list : " );
      for(int i=0; i&lt;list.length ; i++)
      System.out.print(list[i] + " " );
  
      System.out.print("remaining students " );
      for(int i=0; i&lt;list2.length ; i++)
      System.out.print(list2[i] + " " );
    }
  }
  </code></pre>
  
  <p>what is the problem ? it is not working !!!
  in Line 16 it says :</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
        at Q5.main(Q5.java:23)</p>
  </blockquote>
  
  <p>how I can correct this</p>