×
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
2241    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
The world is needed a mixture of truth and make-believe. Discard the make-believe and take the truth.
Sri Sri Ramakrishna Paramahamsa
806
49.97
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     41001
01/01/2018     35638
28/06/2017     33618
25/06/2018     32592
02/08/2017     31869
06/07/2017     26486
01/08/2017     26404
15/05/2017     26074
14/07/2017     21385
21/04/2018     20395
softetechnologies