static void CountWords ( String str , int k ) {
  int sum = 0 ;
  int NumberOfWords = 0 ;
  int counter = 0 ;
  int len = str . length ( ) ;
  for ( int i = 0 ;
  i < len ;
  ++ i ) {
    if ( str . charAt ( i ) == ' ' ) {
      if ( sum < k ) {
        counter ++ ;
      }
      sum = 0 ;
      NumberOfWords ++ ;
    }
    else {
      sum += str . charAt ( i ) ;
    }
  }
  NumberOfWords ++ ;
  if ( sum < k ) {
    counter ++ ;
  }
  System . out . println ( "Number of words having sum " + "of ASCII values less than k = " + counter ) ;
  System . out . println ( "Number of words having sum of " + "ASCII values greater than or equal to k = " + ( NumberOfWords - counter ) ) ;
}

static void CountWords ( String str , int k ) { int sum = 0 ; int NumberOfWords = 0 ; int counter = 0 ; int len = str . length ( ) ; for ( int i = 0 ; i < len ; ++ i ) { if ( str . charAt ( i ) == ' ▁ ' ) { if ( sum < k ) { counter ++ ; } sum = 0 ; NumberOfWords ++ ; } else { sum += str . charAt ( i ) ; } } NumberOfWords ++ ; if ( sum < k ) { counter ++ ; } System . out . println ( " Number ▁ of ▁ words ▁ having ▁ sum ▁ " + " of ▁ ASCII ▁ values ▁ less ▁ than ▁ k ▁ = ▁ " + counter ) ; System . out . println ( " Number ▁ of ▁ words ▁ having ▁ sum ▁ of ▁ " + " ASCII ▁ values ▁ greater ▁ than ▁ or ▁ equal ▁ to ▁ k ▁ = ▁ " + ( NumberOfWords - counter ) ) ; }
(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: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (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 (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (update_expression (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (update_expression (identifier)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))))) (expression_statement (update_expression (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (update_expression (identifier))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (string_literal) right: (string_literal)) right: (identifier))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (string_literal) right: (string_literal)) right: (parenthesized_expression (binary_expression left: (identifier) right: (identifier)))))))))