0% found this document useful (0 votes)
23 views3 pages

Untitled

The document summarizes a student's experiment on writing a Java program to count word frequencies in given text. The student created a program that takes a string as input, converts it to a character array, and uses nested for loops to count the frequency of each unique character. The program then prints the characters and their corresponding frequencies. The student learned to use different data types and the Scanner class. Their performance was evaluated based on demonstration, a worksheet, and a post-lab quiz.

Uploaded by

Sana Sachdeva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Untitled

The document summarizes a student's experiment on writing a Java program to count word frequencies in given text. The student created a program that takes a string as input, converts it to a character array, and uses nested for loops to count the frequency of each unique character. The program then prints the characters and their corresponding frequencies. The student learned to use different data types and the Scanner class. Their performance was evaluated based on demonstration, a worksheet, and a post-lab quiz.

Uploaded by

Sana Sachdeva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment Title - 4

Student Name:SANA SACHDEVA UID: 20BCA1658


Branch: UIC Section/Group: 20BCA5,B
Semester: 4TH Date of Performance: 03/03/22
Subject Name: Internet Programing Lab Subject Code: 22E-20CAP-255

1. Aim/Overview of the practical:


Write a Java Program to make frequency count of words in a given text.

2. Task to be done:
 To create a programme to count words

3. Code for experiment/practical:


 Code for counting words of a string:
package com.company;
public class Main
{
public static void main(String[] args) {
String str = "His name is mohit";
int[] freq = new int[str.length()];
int i, j;

//Converts given string into character array


char string[] = str.toCharArray();

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


freq[i] = 1;
for(j = i+1; j <str.length(); j++) {
if(string[i] == string[j]) {
freq[i]++;
//Set string[j] to 0 to avoid printing visited character
string[j] = '0';
}
}
}

//Displays the each character and their corresponding frequency


System.out.println("Characters and their corresponding frequencies");
for(i = 0; i <freq.length; i++) {
if(string[i] != ' ' && string[i] != '0')
System.out.println(string[i] + "-" + freq[i]);
}
}
}
4. Result/Output/Writing Summary:
Learning outcomes (What I have learnt):

1. Learned to use different data types


2. And learned to use Scanner

Evaluation Grid:

Sr. No. Parameters Marks Obtained Maximum Marks


1. Demonstration and 5
Performance
2. Worksheet 10
3. Post Lab Quiz 5

You might also like