我正在尝试一些新波士顿的练习视频,但无法使其发挥作用!我对java很陌生,这是我的第一个类。我有一个要做二维数组的作业,但我不知道如何让它显示在屏幕上。这个实践来自 Thenewboston 的 Java 教程,视频 # 34,它对他很有效!
public class inventory {
public static void main (String[] args) {
int firstarray[][]= {{8,9,10,11},{12,13,14,15}};
int secondarray[][]={{30,31,32,33},{43},{4,5,6}};
System.out.println("This is the first array");
display(firstarray);
System.out.println("This is the second array");
display(secondarray);
}
public static void display (int x[][])
{
for(int row=0;row<x.length;row++)
{
for(int column=0;column<x.length;column++);
System.out.print(x[row][column]+"\t");
}
{
System.out.println();
}
} }
最佳答案
您在 for 循环之后放置了一个 ;
,否定了您认为是其主体的内容。摆脱
for(int column=0;column<x.length;column++); // <--- this ;
在这种情况下,for
循环的主体(其中声明了 column
变量并具有作用域)是 )
之后的所有内容,并且在 ;
之前。换句话说,什么也没有。您实际上需要将 ;
替换为 {
。
正确的缩进对于帮助您编写语法正确的代码大有帮助。
关于java - "Column"无法解析为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19304775/