java word count 1

java word count

 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.");
        
        
    }

Here is what the above code is Doing:
1. We create a string called example.
2. We create a variable called length and set it equal to the number of words in the string.
3. We print out the length of the string.

Similar Posts