我用 Java 创建了一个存储座位号(行、列)的二维数组。我已经初始化了该数组,以便所有值都从 0 开始,如果后来使用另一种方法 Sit 占用了座位,则该坐标处的值为 1。
这是初始化:
int[][] seatlist= new int[FIRSTCLASS/3][3];
for (int i=0; i<= FIRSTCLASS/3; i++)
{
for (int j=0; j<3; j++)
{
seatlist[i][j]=0;
}
}
这是我的方法:
public boolean canSit(int seatrow, int seatcolumn)
{
if(seatlist[seatrow-1][seatcolumn-1]==0)
{
return true;
}
else
return false;
}
当我尝试编译时,我在 if 语句行上不断收到“需要数组,但找到了 int”错误。我无法确定问题所在 - 有人可以帮忙吗?
提前致谢!
最佳答案
试试这个。
Integer[][] seatlist= new Integer[FIRSTCLASS/3][3];
或
int[FIRSTCLASS/3][3] seatlist;
关于java - If 语句中的二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15857706/