0% found this document useful (0 votes)
5 views1 page

Java 17 Word Frequency Counter

The document describes a Java program that counts the frequency of words in given text. The program takes text as input, splits it into words, and counts the occurrences of a given search word. It outputs the frequency of the searched word.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Java 17 Word Frequency Counter

The document describes a Java program that counts the frequency of words in given text. The program takes text as input, splits it into words, and counts the occurrences of a given search word. It outputs the frequency of the searched word.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

[Link]: 17 Exp. Name: Write a Java program to make frequency count of words in a given text.

Date: 2022-06-15

ID: 20095A0363
    Page No:
           
Aim:
Write a Java program to make frequency count of words in a given text.
Source Code:

[Link]

import [Link].*;

class WordCount {

public static void main(String args[])throws IOException {

BufferedReader br = new BufferedReader(new InputStreamReader([Link]));

[Link]("Enter some text: ");

String s = [Link]();

[Link]("Enter the word whose frequency is to be found: ");

String sub = [Link]();

int ind,count = 0;

String str[] = [Link](" ");

for(int i = 0;i<[Link];i++)

if(str[i].equals(sub))

count++;

[Link]("The frequency of word '"+ sub +"' is: "+count);

    Rajeev Gandhi Memorial College of Engineering and Technology (Autonomous)      2019-2023-MECH-FDH


}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output
Enter some text: The first second was alright, but the second second was tough
Enter the word whose frequency is to be found: second
The frequency of word 'second' is: 3

Test Case - 2

User Output
Enter some text: Hello world! Hello John! Hello everyone!
Enter the word whose frequency is to be found: Hello
The frequency of word 'Hello' is: 3

You might also like