Answers for "java program to count no of words in a sentence"

3

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.");
        
        
    }
Posted by: Guest on June-04-2020

Code answers related to "java program to count no of words in a sentence"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language