Skip to main content

Practice · 3 of 6

Count words with messy spacing

CHALLENGE
Difficulty: intermediate+25 XP

Count the **words** in a string: maximal runs of non-space characters separated by one or more spaces. Leading, trailing, and repeated spaces must not create phantom words. Implement process(String s) returning the count (0 for empty/all-space). Example: " hello world " → 2.

Back to lesson: Practice: String lab: transformations under constraints