-2
代码未运行?尝试将值输入到2d数组并打印出来,代码未运行
import java.util.Scanner;
public class Array2dNightPractice
{
int[][] studentmarks;
studentmarks = new int[3][3];
Scanner kb = new Scanner(System.in);
System.out.println("Enter 9 integers");
for(int row = 0;row<3;row++){
for(int col=0;col<3;col++){
studentmarks[row][col] = kb.nextInt();
}
}
for(int row = 0; row < 3; row++) {
for(int col = 0; col < 4; col++) {
System.out.print(studentmarks[row][col] + " ");
}
System.out.println();
}
}
什么是错误?请详细说明你的问题。 – rotgers
这个for(int col = 0; col <4; col ++)'可能会给你一个错误,因为只有3个索引。没有'studentmarks [3] [4]'。它显然应该是for(int col = 0; col <3; col ++)'。 – rotgers
你应该看到索引超出范围错误?你看到了吗? –