問題:
ドロップ期間の終了後に学生の成績のリストを更新するプログラム。プログラムは、ドロップした学生のユーザー番号とそのインデックスから読み取り、残りの学生の成績を新しい配列にコピーする必要があります。さらに、プログラムは元のリストと更新されたリストの両方を表示する必要があります。[ヒント: 新しい配列には、残りの生徒数に相当する適切な長さが必要です]
私のコード:
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<=num ; j++)
{
System.out.println("student" + j + ":");
int index=scan.nextInt();
list[index]=0;
}
int j=0;
for(int i=0; i<list.length ; i++)
if (list[i]!=0)
{
list2[j]=list[i];
j++;
}
System.out.print("The original list : " );
for(int i=0; i<list.length ; i++)
System.out.print(list[i] + " " );
System.out.print("remaining students " );
for(int i=0; i<list2.length ; i++)
System.out.print(list2[i] + " " );
}
}
何が問題ですか ?それは機能していません!!! 16行目には次のように書かれています:
スレッド「メイン」での例外 java.lang.ArrayIndexOutOfBoundsException: 4 at Q5.main(Q5.java:23)
これを修正するにはどうすればよいですか