Problem:
Return true if the given string contains between 1 and 3 'e' chars.
stringE("Hello") → true
stringE("Heelle") → true
stringE("Heelele") → false
Solution:
public boolean stringE(String str) {
  int len = str.length();
  int counter = 0;
  
  for (int i = 0; i < len; i++) {
    if (str.charAt(i) == 'e')
      counter++;
  }
  
  if (counter >= 1 && counter <= 3)
    return true;
  else
    return false;
}
 

 
No comments :
Post a Comment