×
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
2997    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.
Sri Sri Ramakrishna Paramahamsa
Do yourself what you wish others to do.
Sri Sri Ramakrishna Paramahamsa
5341
71.18
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     51691
25/06/2018     43586
01/01/2018     42719
28/06/2017     40444
02/08/2017     39248
01/08/2017     33493
06/07/2017     33215
15/05/2017     32608
14/07/2017     28811
11/09/2018     28564
softetechnologies