If you split on the spaces, then each element of the resulting array will be a word. Therefore, the number of words is equal to the number of elements in the array, which you can access with the "length" variable.
int wordCount = output.length;
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org