×
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
2569    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.
Rabindranath Tagore
It is very simple to be happy, but it is very difficult to be simple.
Rabindranath Tagore
985
58.53
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     44001
01/01/2018     36614
25/06/2018     35920
28/06/2017     34654
02/08/2017     33154
01/08/2017     27623
06/07/2017     27341
15/05/2017     26989
14/07/2017     22634
21/04/2018     21243
softetechnologies