Return the number of times that the string "hello" appears anywhere in the given string.
Sample Input #1
count("abc hello def")
Sample Output #1
1
Sample Input #2
count("Hi. Hello. Hello. Ok")
Sample Output #2
2
Sample Input #3
count("hi")
Sample Output #3
0
MyApproach
public int count(String str)
{
String str1="Hello";
int l1=str.length();
int l2=str1.length();
if(l1<l2)
{
return 0;
}
else
{
int count=0;
int p=0;
for(int j=0;j<l1;j++)
{
if( (c1==(c2+32)) || (c1==(c2-32)))
{
p++;
}
if(p==l1)
{
count++;
p=0;
}
}
return count;
}
//write your code here
}
}
Output TestcaseParameters Testcase Actual Answer Expected
No output Hello how are you' null 1
I am getting the following output.
Can anyone tell me what I am doing wrong?
Aucun commentaire:
Enregistrer un commentaire