Write a method called wordCount that accepts a String as its parameter and returns the number of words in the String. A word is a sequence of one or more nonspace characters
If you want to ignore leading, trailing and duplicate spaces you can use
String trimmed = text.trim(); int words = trimmed.isEmpty() ? 0 : trimmed.split("\\s+").length;