Skip to main content

Frequency Count Of Words in a Given Text

import java.io.*;
import java.util.*;
class Fre_count  
{
 public static void main(String[] args) throws IOException
 {
  BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
  System.out.println("enter a string");
  String a=new String(b.readLine());
  System.out.println("enter the word you want to find the count");
  String c=new String(b.readLine());
  StringTokenizer s=new StringTokenizer(a);
  int i=s.countTokens();
  int k=0,j=0;
  String tok[]=new String[i];
  while(s.hasMoreTokens())
  {
   tok[j++]=s.nextToken();
  }

  for(j=0;j<tok.length;j++)
  {
   if(c.equals(tok[j]))
    k++;
  }
  System.out.println("frequency count of "+c+" is "+k);
 }
}

Comments

Popular posts from this blog

Find Value of S=ut+1/2*a*t**2.

PROCEDURE:-        1.enter values for u,a,t to find distance        2.find distance with the formulae ut+1/2at 2        3.print the above result CODE:- #include<stdio.h> #include<conio.h> void main() {   float u,t,a,S;   clrscr();   printf(“enter values u,t,a”);   scanf(“%f %f %f”, &u,&t,&a);   S=(u*t)+(0.5*a*t*t);   printf(“\n  S = %f”, S); } Input:- enter values u,t,a               U=10,t=4,a=4.9 Output:- S =79.200