Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Can you people please say how a for loop works in multi dimensional arrays? ex: matrix multiplication /sorting 2 string arays usin compareTo() method

user-image
Question added by ramaswami s
Date Posted: 2013/11/11
Daanish Rumani
by Daanish Rumani , Product Manager , Publicis Sapient

int[3][4] matrix = new int[3][4];

fillMatrix(matrix);

for(int i =0; i < matrix.length; ++i) {

    for(int j =0; j < matrix[i].length; ++j)  {

        // access matrix[i][j] and do something

    }

}

Deleted user
by Deleted user

Your example is not clear. However, nested for-loops are what is used for multidimensional arrays, which are called matrices once they're above1 dimension.

More Questions Like This