我正在尝试一些练习新波士顿的视频,但无法让这个工作!我是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();
}
Run Code Online (Sandbox Code Playgroud)
}}
你;在for循环之后放了一个,否定了你认为它的身体.摆脱
for(int column=0;column<x.length;column++); // <--- this ;
Run Code Online (Sandbox Code Playgroud)
在这种情况下,for循环体column(声明变量并具有范围)是在)之前和之后的所有内容;.换句话说,没什么.你实际上需要;用a 代替{.
正确的缩进将帮助您编写语法正确的代码.