id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

orion.a.smith@gmail.com apcsa-loops > apcsaChatbotsCountWords
prev  |  next  |  chance

Given an input String, find the number of words. For this problem, a word is defined very simply as any set of characters which are not spaces. Preconditions: all words will be separated by only one space, and each input will contain one or more words. Also, no inputs will begin or end with spaces (for that bit of fun, see the next problem).


HINT: think about how many spaces there are in the input.

apcsaChatbotsCountWords("Hello world") → 2
apcsaChatbotsCountWords("Hello to the world") → 4
apcsaChatbotsCountWords("Wonderful") → 1

...Save, Compile, Run (ctrl-enter)

public int apcsaChatbotsCountWords(String str) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 210

Copyright Nick Parlante 2017 - privacy