×
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
3325    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.
Albert Einstein
The only source of knowledge is experience.
Albert Einstein
2370
80.75
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     54110
25/06/2018     45116
01/01/2018     43670
28/06/2017     41205
02/08/2017     40216
01/08/2017     34263
06/07/2017     34062
15/05/2017     33299
11/09/2018     30314
14/07/2017     29827
softetechnologies