count number of words in a string java without class code example
Example: count the number of words in a string java
public static void main(String[] args)
{
//return the number of words in a string
String example = "This is a good exercise";
int length = example.split(" ").length;
System.out.println("The string is " + length + " words long.");
}