public static void getSmallestAndLargest ( String s , int k ) {
  String currStr = s . substring ( 0 , k ) ;
  String lexMin = currStr ;
  String lexMax = currStr ;
  for ( int i = k ;
  i < s . length ( ) ;
  i ++ ) {
    currStr = currStr . substring ( 1 , k ) + s . charAt ( i ) ;
    if ( lexMax . compareTo ( currStr ) < 0 ) lexMax = currStr ;
    if ( lexMin . compareTo ( currStr ) > 0 ) lexMin = currStr ;
  }
  System . out . println ( lexMin ) ;
  System . out . println ( lexMax ) ;
}

public static void getSmallestAndLargest ( String s , int k ) { String currStr = s . substring ( 0 , k ) ; String lexMin = currStr ; String lexMax = currStr ; for ( int i = k ; i < s . length ( ) ; i ++ ) { currStr = currStr . substring ( 1 , k ) + s . charAt ( i ) ; if ( lexMax . compareTo ( currStr ) < 0 ) lexMax = currStr ; if ( lexMin . compareTo ( currStr ) > 0 ) lexMin = currStr ; } System . out . println ( lexMin ) ; System . out . println ( lexMax ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (identifier))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (identifier))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) 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: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (identifier)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))