PDA

View Full Version : Size of a Matrix in java (solved)




Eraserhead
Jul 10, 2006, 06:12 AM
I know that to calculate the size of a 1D matrix in Java you use .length (so if you create a vector v using

int [] v= new int [3];
System.out.println(v.length);


It will print 3, but if I have a matrix A

int [][] A=new int[3][4];
System.out.println(A.length);

It will also print 3, but how do you get it to print the other dimension (in this case 4)?

Thanks



Mitthrawnuruodo
Jul 10, 2006, 06:18 AM
It's been a while, and my memory might fool me, but wasn't it:

System.out.println(A[0].length);

Eraserhead
Jul 10, 2006, 06:20 AM
It's been a while, and my memory might fool me, but wasn't it:

System.out.println(A[0].length);
Yep that works, thanks :)