import java.util.*;
class Frequency
{
int i,c=0;
String str,s,word;
Scanner sc=new Scanner(System.in);
public void take()
{
System.out.print("\nEnter the sentence:");
str=sc.nextLine();
str=str+" ";
System.out.print("\nEnter the word:");
word=sc.nextLine();
while(true)
{
i=str.indexOf(' ');
if(i<0)
break;
s=str.substring(0,i);
str=str.substring(i+1);
if(s.equals(word))
c++;
}
System.out.print("\nFrequency of the word "+word+ " is: "+c);
}
public static void main(String args[])
{
Frequency ob=new Frequency();
ob.take();
}
}
No comments:
Post a Comment