简体   繁体   English

If语句中的2D数组

[英]2D Array in an If Statement

I've created a 2D Array in Java that stores seatnumbers(row, column). 我在Java中创建了一个2D数组,用于存储座位号(行,列)。 I've initialized the array so that all values start out as 0, and if the seat is later occupied using another method Sit, the value at that coordinate is 1. 我已经初始化了数组,以使所有值都开始为0,并且如果以后使用另一种方法Sit占用了座位,则该坐标处的值为1。

Here is the intializing: 这是初始化:

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;

       }
    }

and here is my method: 这是我的方法:

public boolean canSit(int seatrow, int seatcolumn)
{ 
    if(seatlist[seatrow-1][seatcolumn-1]==0) 
    { 
        return true;
    } 
    else 
        return false; 
}

When I try compiling, I keep getting an "array required, but int found" error on the if statement line. 当我尝试编译时,在if语句行中不断收到“需要数组,但找到int”错误。 I can't identify the problem- can anyone help? 我无法确定问题所在-任何人都可以帮忙吗?

Thanks in advance! 提前致谢!

Try this. 尝试这个。

Integer[][] seatlist= new Integer[FIRSTCLASS/3][3];

or 要么

int[FIRSTCLASS/3][3] seatlist;  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM