public static String foo ( String s ) throws Exception {
  if ( s . length ( ) == 0 ) return "" ;
  int last = 'A' ;
  for ( int i = 0 ;
  i < s . length ( ) ;
  i ++ ) {
    last = Math . max ( last , s . charAt ( i ) ) ;
  }
  for ( int i = s . length ( ) - 1 ;
  i >= 0 ;
  i -- ) {
    if ( s . charAt ( i ) == last ) {
      return ( char ) ( last ) + foo ( s . substring ( 0 , i ) ) + s . substring ( i + 1 ) ;
    }
  }
  throw new Exception ( "BANANAS" ) ;
}

public static String foo ( String s ) throws Exception { if ( s . length ( ) == 0 ) return " " ; int last = ' A ' ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { last = Math . max ( last , s . charAt ( i ) ) ; } for ( int i = s . length ( ) - 1 ; i >= 0 ; i -- ) { if ( s . charAt ( i ) == last ) { return ( char ) ( last ) + foo ( s . substring ( 0 , i ) ) + s . substring ( i + 1 ) ; } } throw new Exception ( " BANANAS " ) ; }
(method_declaration (modifiers) type: (type_identifier) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier))) (throws (type_identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) consequence: (return_statement (string_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (character_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier))) consequence: (block (return_statement (binary_expression left: (binary_expression left: (cast_expression type: (integral_type) value: (parenthesized_expression (identifier))) right: (method_invocation name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier)))))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))))))))) (throw_statement (object_creation_expression type: (type_identifier) arguments: (argument_list (string_literal))))))