|
Hello,
I'm trying to write two methods, one will tell me how many rows in the array and one will tell me how many columns in the array. I'm not sure how to do this.
Signature of method for number of rows:
public int numOfRows()
{
}
I also need to write a method for number of columns:
public int numOfColumns()
{
}
What I'm used to doing is using the .length method but that only gives me the number of rows in the array. It would look like:
return grid.length; (where grid is the name of the array)
Thanks,
Maig
|
|
|
public class Test
{
static int[][] testArray = new int[7][4];
public static void main(String[] args)
{
System.out.println("rowCount = " + numberOfRows() + "\n" +
"colCount = " + numberOfColumns());
}
private static int numberOfRows()
{
return testArray.length;
}
private static int numberOfColumns()
{
return testArray[0].length;
}
}
|
|
|
|
|
|
|
|
|
|
|
// |