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

Java 17

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)
7 views1 page

Java 17

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
You are on page 1/ 1

S.No: 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:

WordCount.java

import java.io.*;

class WordCount {

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

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter some text: ");

String s = br.readLine();

System.out.print("Enter the word whose frequency is to be found: ");

String sub = br.readLine();

int ind,count = 0;

String str[] = s.split(" ");

for(int i = 0;i<str.length;i++)

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

count++;

System.out.println("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