1

int を int[] に変換できないというエラーが表示されます。

//Create array
int [][] studentResults = new int [numStudents][numExams];

//Fill 1st dimension with Student numbers 1 through numStudents
for (int count = 0; count < numStudents; count++)
    studentResults[count][] = count + 1;
4

2 に答える 2

1

Java では、配列内のエントリに値を割り当てる場合、配列のすべてのインスタンスを指定する必要があります。次のことをお勧めします。

//Create array
int [][] studentResults = new int [numStudents][numExams];

//This loops through the two dimensional array that you created 
//And fills the 1st dimension with Student numbers 1 through numStudents.
for (int count = 0; count < numStudents; count++)
    for (int exam = 0; exam < numExams; exam++)
        studentResults[count][exam] = count + 1;

studentResultsこれにより、各生徒のすべての試験エントリを反復処理します。

于 2013-06-25T02:13:01.317 に答える