Program to count number of words in a String?

Source Code:

public class CountWordsString {
public static void main(String[] args) {
String s = “Java is very easy”;
String[] words = s.split(“\s+”);
System.out.println(words.length);
}
}

Output: