public static boolean lookForIt(String str, String letter) {
int c = 0;
for (int i = 0; i < str.length(); i++)
if (str.substring(i, i + 1).equals(letter))
c++;
return c >= 2;
}
Function Call | Return Value | |||
---|---|---|---|---|
lookForIt("aaabbb", "a") | → | |||
lookForIt("bbba", "b") | → | |||
lookForIt("aa", "c") | → | |||
lookForIt("a", "d") | → | |||
lookForIt("", "e") | → |
Experiment with this code on Gitpod.io