← Unit 4 · all exercises
Saved in this browser only

Count the words

Return how many words are in the sentence, where words are separated by single spaces. An empty String has no words.

int wordCount(String sentence)

Solution.java
Loading editor…
Results

Examples

  • Solution.wordCount("hello there world") → 3
  • Solution.wordCount("one") → 1

There are also 3 hidden tests you can't see. Solve the problem, not the examples.