Count the number of times a particular word occurs in it


Write a program to enter a sentence from the keyboard and count the number of times a particular word occurs in it. Display the frequency of the search word.

import java.util.*;

public class Frequency
{
public static void main(String[] args)
{
char c;
int ent = 0;
Scanner sc = new Scanner (System.in);
System.out.println("ENTER A SENTENCE " );
String s = sc.nextLine();
System.out.println("ENTER A WORD TO BE SEARCHED " );
String w = sc.nextLine();
String n = "";
for(int i = 0; i<s.length();i++)
{
c=s.charAt(i);
if(c==' '||c=='.')
{
if(n.equals(w))
ent = ent+1;
n="";
}
else
{
n=n+c;
}
}
System.out.println("FREQUENCY OF WORD IS : " + ent);
}
}

FOR CODE ,
CLICK : https://onecompiler.com/java/3xymqxpu5 (TO FIND OUTPUT)