in JAVA by
Write a Java program to count the number of words present in a string?

1 Answer

0 votes
by

Program:

  public class Test   

{  

    public static void main (String args[])  

    {  

        String s = "Sharma is a good player and he is so punctual";  

        String words[] = s.split(" ");  

        System.out.println("The Number of words present in the string are : "+words.length);  

    }  

}  

Output

The Number of words present in the string are : 10

Related questions

+2 votes
asked May 13, 2021 in JAVA by rajeshsharma
0 votes
asked Oct 24, 2020 in JAVA by sharadyadav1986
0 votes
asked Mar 16, 2021 in JAVA by Robindeniel
...