Daffodil
Company
Programming
Program
Wap to count the no. of times a word is repeated in given string. for example: who are you and where are you from you two times are two times
Read Solution (Total 4)
-
- class Str_Count
{
public static void main(String ar[])
{
String str="How are you , Where are you";
String match="you";
int count=0;
String a[]=str.split(" ");
for (int i=0;i - 6 years agoHelpfull: Yes(1) No(1)
- this is to be done by using ASCII value
- 8 years agoHelpfull: Yes(0) No(2)
- public class Test
{
static int wordCount(String str,String word)
{ String a[]=str.split(" ");
int count=0;
for(int i=0;i - 5 years agoHelpfull: Yes(0) No(0)
- #include
#include
#include
int main()
{
char string[100], word[20], unit[20], c;
int i = 0, j = 0, count = 0;
printf("Enter string: ");
i = 0;
do
{
fflush(stdin);
c = getchar();
string[i++] = c;
} while (c != 'n');
string[i - 1] = ' ';
printf("Enter the word you want to find: ");
scanf("%s", word);
for (i = 0; i < strlen(string); i++)
{
while (i < strlen(string) && !isspace(string[i]) && isalnum(string[i]))
{
unit[j++] = string[i++];
}
if (j != 0)
{
unit[j] = ' ';
if (strcmp(unit, word) == 0)
{
count++;
}
j = 0;
}
}
printf("The number of times the word '%s' found in '%s' is '%d'.n", word, string, count);
} - 5 years agoHelpfull: Yes(0) No(0)
Daffodil Other Question