Поскольку вы пометили «java» своим вопросом, вот простой код java для подсчета количества слов путем разделения на пробелы.
public class Splitting {
public static void main(String[] args) {
String inputLines = "This class is for split words by spaces and count the number of words";
String[] words = inputLines.split(" ");
System.out.println(Arrays.toString(words));
System.out.println("No of words: "+words.length); }
}
output:
[This, class, is, for, split, words, by, spaces, and, count, the, number, of, words]
No of words: 14
Надеюсь, это как-нибудь поможет!