📅  最后修改于: 2022-03-11 14:52:25.858000             🧑  作者: Mango
String name = "Carmen is a fantastic play"; //arbitrary sentence
int numWords = (name.split("\\s+")).length; //split string based on whitespace
//split returns array - find legth of array
System.out.println(numWords);