private static void printMatrix ( int mat [ ] [ ] , int m , int n , int i , int j , int path [ ] , int idx ) {
  path [ idx ] = mat [ i ] [ j ] ;
  if ( i == m - 1 ) {
    for ( int k = j + 1 ;
    k < n ;
    k ++ ) {
      path [ idx + k - j ] = mat [ i ] [ k ] ;
    }
    for ( int l = 0 ;
    l < idx + n - j ;
    l ++ ) {
      System . out . print ( path [ l ] + " " ) ;
    }
    System . out . println ( ) ;
    return ;
  }
  if ( j == n - 1 ) {
    for ( int k = i + 1 ;
    k < m ;
    k ++ ) {
      path [ idx + k - i ] = mat [ k ] [ j ] ;
    }
    for ( int l = 0 ;
    l < idx + m - i ;
    l ++ ) {
      System . out . print ( path [ l ] + " " ) ;
    }
    System . out . println ( ) ;
    return ;
  }
  printMatrix ( mat , m , n , i + 1 , j , path , idx + 1 ) ;
  printMatrix ( mat , m , n , i , j + 1 , path , idx + 1 ) ;
}

private static void printMatrix ( int mat [ ] [ ] , int m , int n , int i , int j , int path [ ] , int idx ) { path [ idx ] = mat [ i ] [ j ] ; if ( i == m - 1 ) { for ( int k = j + 1 ; k < n ; k ++ ) { path [ idx + k - j ] = mat [ i ] [ k ] ; } for ( int l = 0 ; l < idx + n - j ; l ++ ) { System . out . print ( path [ l ] + " ▁ " ) ; } System . out . println ( ) ; return ; } if ( j == n - 1 ) { for ( int k = i + 1 ; k < m ; k ++ ) { path [ idx + k - i ] = mat [ k ] [ j ] ; } for ( int l = 0 ; l < idx + m - i ; l ++ ) { System . out . print ( path [ l ] + " ▁ " ) ; } System . out . println ( ) ; return ; } printMatrix ( mat , m , n , i + 1 , j , path , idx + 1 ) ; printMatrix ( mat , m , n , i , j + 1 , path , idx + 1 ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))) update: (update_expression (identifier)) body: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (string_literal))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list))) (return_statement))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))) update: (update_expression (identifier)) body: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (string_literal))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list))) (return_statement))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier) (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal))))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier) (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)))))))