I have this 2d array:
private boolean[][] landscape;
this landscape array defines a pond with its [rows] and [cols]
The method, public int getRows()
, needs to return the number of rows in the landscape array
I tried just return landscape.length;
and that didnt work. Couple more things I tried without success:
int count = 0;
for (boolean[] i : landscape){
count += i.length;
}
return count;
And
int count = 0;
for (int i = 0; i < landscape.length; i++) {
if (landscape[i] != null){
count ++;
}
}
return count;
The amount of rows and cols depends on what the user selects I believe. There is a minimum of 5. So how would i do this?