Following are the test cases
Test cases | Result | Status |
---|---|---|
stringE(Hello) | true | OK |
stringE(Heelele) | false | OK |
stringE(Heelle) | true | OK |
Java solution
package test;
public class Program16 {
public static void main(String[] args) {
Program16.stringE("Hello");
Program16.stringE("Heelele");
Program16.stringE("Heelle");
}
public static boolean stringE(String str) {
char[] letters = str.toCharArray();
int count = 0;
for (int i = 0; i < letters.length; i++) {
if (letters[i] == 'e') {
count++;
}
}
if (count == 1 || count == 3) {
return true;
}
return false;
}
}
Javascript solution
const stringE = (str) => {
let count = 0;
for (let i = 0; i < str.length; i++) {
if (str[i] === 'e') {
count++;
}
}
if (count === 1 || count === 3) {
return true;
}
return false;
}
console.log(stringE('Hello')); //true
console.log(stringE('Heelele')); //false
console.log(stringE('Heelle')); //true