I need to count the number of words and I am assuming the correct way to do it is by calculating the number of times that the previous character in a string is not a letter
You can use String.split() to convert the string into an array, with one word in each element. The number of words is given by the length of the array: