Java 创建二维数组并用1变量填充第一个数组
我收到一个错误,无法将int转换为int[],有人能帮忙吗Java 创建二维数组并用1变量填充第一个数组,java,Java,我收到一个错误,无法将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][]
//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;
//创建数组
int[]studentResults=新int[numStudents][numExams];
//用学生编号1到numStudents填充第一维度
对于(int count=0;count
在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;
//创建数组
int[]studentResults=新int[numStudents][numExams];
//这将遍历您创建的二维数组
//并用学生编号1到numStudents填充第一个维度。
对于(int count=0;count
从而对每个学生的
studentResults
的每个考试条目进行迭代。因此您需要设置每行第一列的值。正如我们所知,第一列索引是0。因此,对于每一行,设置数组的0列,如下所示
for (int count = 0; count < numStudents; count++)
studentResults[count][0] = count + 1;
for(int count=0;count
您到底想做什么?尝试创建二维数组。第一个填写一些学生,第二个填写用户输入的考试分数。用户可以检查最终成绩,无需设置其他列值。。只需要设置第一列