我有这个2d数组:
private boolean[][] landscape;
Run Code Online (Sandbox Code Playgroud)
这个景观数组定义了一个有[行]和[cols]的池塘
该方法public int getRows()需要返回格局数组中的行数
我试过了return landscape.length;,但没有用.结合我尝试的更多事情没有成功:
int count = 0;
for (boolean[] i : landscape){
count += i.length;
}
return count;
Run Code Online (Sandbox Code Playgroud)
和
int count = 0;
for (int i = 0; i < landscape.length; i++) {
if (landscape[i] != null){
count ++;
}
}
return count;
Run Code Online (Sandbox Code Playgroud)
行和列的数量取决于用户选择的内容.至少有5.所以我该怎么做?