Size of a Matrix in java (solved)

Discussion in 'Mac Programming' started by Eraserhead, Jul 10, 2006.

  1. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #1
    I know that to calculate the size of a 1D matrix in Java you use .length (so if you create a vector v using
    Code:
    int [] v= new int [3];
    System.out.println(v.length);
    
    It will print 3, but if I have a matrix A
    Code:
    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
     
  2. Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #2
    It's been a while, and my memory might fool me, but wasn't it:

    System.out.println(A[0].length);
     
  3. thread starter macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #3
    Yep that works, thanks :)
     

Share This Page