Loop to print the matrix
for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) System . out . print ( a [ i ] [ j ] + " ▁ " ) ; System . out . println ( ) ; } } static void swap ( int [ ] [ ] a , int i , int i2 , int pos , int pos2 ) { int temp = a [ i ] [ i2 ] ; a [ i ] [ i2 ] = a [ pos ] [ pos2 ] ; a [ pos ] [ pos2 ] = temp ; }