## Problem:

Return the number of times that the string "hi" appears anywhere in the given string.

countHi("abc hi ho") → 1
countHi("ABChi hi") → 2
countHi("hihi") → 2

## Solution:

public int countHi(String str) {
int count =0;
if (str.length() ==1 && str.charAt(0) == 'h')
count = 0;
else
{
for(int i = 0;i<str.length();i++) {
if ( (str.charAt(i) == 'h') && (str.charAt(i+1) == 'i') )
count+=1;
}
}
return count;
}


1. public int countHi(String str) {
int count = 0;
for(int i=0; i<str.length()-1; i++){
if(str.charAt(i) == 'h' && str.charAt(i+1) == 'i')
count++;
}
return count;
}

2. int count = 0;
for (int i = 0; i < str.length() - 1; i++){
if (str.charAt(i) == 'h' && str.charAt(i + 1)== 'i')
count += 1;
}
return count;

3. public int countHi(String str) {
int count = 0;
for (int i=0; i<str.length(); i++){
if (str.substring(i).startsWith("hi")) count++;
}return count;
}

4. public int countHi(String str) {
String found = "hi";
int full = str.length();
str = str.replace(found, "");
int cut = str.length();
return (full - cut) / found.length();
}

5. public int countHi(String str) {
if(str.isEmpty()|| str.length() <= 1){
return 0;
}
if(str == "hi"){
return 1;
}
else
{
int L =str.length();

if(str.charAt(L-2) == 'h' && str.charAt(L-1) == 'i'){
return 1 + countHi(str.substring(0,L-2));
}
else
{
return countHi(str.substring(0,L-1));
}

}

}

6. public int countHi(String str) {
int count=0;
for(int i=0;i<str.length()-1;i++){
if((str.charAt(i)=='h')&&(str.charAt(i+1)=='i'))count++;
}
return count;
}