java Program to find bo of occurances of words code example
Example 1: check how many of a word is in a string
function countOccurences(str,word)
{
String a[] = str.split(",");
int count = 0;
for (int i = 0; i < a.length; i++)
{
if (word.equals(a[i]))
count++;
}
return count;
}
Example 2: Write a c++ program that reads a sentence (including spaces) and a word, then print out the number of occurrences of the word in the sentence
Write a c++ program that reads a sentence (including spaces) and a word, then print out the number of occurrences of the word in the sentence