Function to print valid matrix
public static void printMatrix ( char arr [ ] [ ] , int n , int m ) { place ( arr , n , m ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { System . out . print ( arr [ i ] [ j ] ) ; } System . out . println ( ) ; } }