打印多维数组(Java)的元素时出错
我想打印矩阵的所有元素。但是编译器抛出“找不到符号”错误。我想知道确切的问题和解决办法
class Main{
public static void main(String[] args){
int[][] matrix = {
{3, 2, 1},
{3, 2, 1},
{5, 5, 8}
};
for (int[] i : matrix);
for ( int j : i);
System.out.println("At Row "+ i + " at column" + j + " = " + matrix[i][j]);
}
}
# 1 楼答案
艾伦已经指出了你的错误。 如果希望通过foreach循环实现同样的效果:
# 2 楼答案
你有两个问题:
你需要迭代索引,而不是对象
你有一个“;”你应该有一个大括号(“{”)