public static boolean isValid ( String s , int rows , int cols ) {
  int pointer = 0 ;
  char [ ] [ ] grid = new char [ rows ] [ cols ] ;
  for ( int i = 0 ;
  i < rows ;
  i ++ ) {
    for ( int j = 0 ;
    j < cols ;
    j ++ ) grid [ i ] [ j ] = s . charAt ( pointer ++ ) ;
  }
  for ( int j = 0 ;
  j < cols ;
  j ++ ) {
    boolean allX = true ;
    for ( int i = 0 ;
    i < rows ;
    i ++ ) if ( grid [ i ] [ j ] == 'O' ) allX = false ;
    if ( allX ) return true ;
  }
  return false ;
}

public static boolean isValid ( String s , int rows , int cols ) { int pointer = 0 ; char [ ] [ ] grid = new char [ rows ] [ cols ] ; for ( int i = 0 ; i < rows ; i ++ ) { for ( int j = 0 ; j < cols ; j ++ ) grid [ i ] [ j ] = s . charAt ( pointer ++ ) ; } for ( int j = 0 ; j < cols ; j ++ ) { boolean allX = true ; for ( int i = 0 ; i < rows ; i ++ ) if ( grid [ i ] [ j ] == ' O ' ) allX = false ; if ( allX ) return true ; } return false ; }
(method_declaration (modifiers) type: (boolean_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier)) dimensions: (dimensions_expr (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: (identifier)) update: (update_expression (identifier)) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (update_expression (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: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (true))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (character_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (false))))) (if_statement condition: (parenthesized_expression (identifier)) consequence: (return_statement (true))))) (return_statement (false))))