×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Custom Exception Handling in Java Java String Programs - Find word in java
Java String Programs - Word Count in java - Java
2436    Arnab De    14/03/2018

Write a program in java to find out the frequency of words in a sentence.



It is very simple program just split the sentence in string array using split() methods of String class and get the length of the array by using the length property of array.

import java.util.*;
class WordCount
{
    public static void main(String []args)
    {
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter a String:");
        String str=sc.nextLine();
        String []words=str.split(" "); //split the sentence into words
        System.out.println("No Of Words : " + words.length);
    }
}



softetechnologies

Related program
Write a program in java to find out the frequency of spaces in a sentance.

Total no space is equal to the ( no of word - 1)


import java.util.*;
class SpaceCount
{
    public static void main(String []args)
    {
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter a String:");
        String str=sc.nextLine();
        String []words=str.split(" "); //split the sentence into words
        System.out.println("No Of Space : " + (words.length-1));
    }
}

softetechnologies
Custom Exception Handling in Java Java String Programs - Find word in java
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Swami Vivekananda
A nation is advanced in proportion to education and intelligence spread among the masses.
Swami Vivekananda
1240
54.77
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     42670
01/01/2018     36200
25/06/2018     34346
28/06/2017     34315
02/08/2017     32629
01/08/2017     27143
06/07/2017     26970
15/05/2017     26598
14/07/2017     22165
21/04/2018     20856
softetechnologies