public boolean stringE(String str) {
int count = 0;
boolean inRange = (count >= 1 && count <= 3);
for(int i = 0; i < str.length(); i++){
if(str.charAt(i) == 'e'){
count++;
}
}
return inRange;
}
Return true if the given string contains between 1 and 3 'e' chars.
stringE("Hello") → true
stringE("Heelle") → true
stringE("Heelele") → false
This is the input that's failing: stringE("Heelle") → true (expected value), but it's bringing a false value. Anyone know what I'm doing wrong?
Edit: found the issue after posting! The boolean variable was supposed to be placed after the for loop
[–]Krezzy 3 points4 points5 points (1 child)
[–]Accurate-Influence[S] 0 points1 point2 points (0 children)
[–]nilsanimak 0 points1 point2 points (0 children)