I have a function which takes 2D array. I am wondering if there is anyway to get rows and columns of the 2D array without having to iterate on it. Method signature is not to be changes.
Function is inside the ninetyDegRotator class.
public static int [][] rotate(int [][] matrix){
int [][] rotatedMatrix = new int[4][4];//need actual row n col count here
return rotatedMatrix; //logic
}
And main code is
public static void main(String args[]){
int [][] matrix = new int[][]{
{1,2,3,4},
{5,6,7,8},
{9,0,1,2},
{3,4,5,6}
};
System.out.println("length is " + matrix.length);
int [][] rotatedMatrix = ninetyDegRotator.rotate(matrix);
}
Also matrix.length gives me 4. So I guess it is number of rows that it gives meaning number of references in 1D array which themselves contain arrays. So is there a way to get the count without iterating?