You are checking character against String array. You need to check the char against the char in the array
if(s[i].charAt(j) ==ch){
counter++;
}
And you are returning wrong.
So your code becomes
public static int charFrequency(String[] s, char ch) {
int counter = 0;
for (int i = 0; i < s.length; i++) {
for (int j = 0; j < s[i].length(); j++) {
if (s[i].charAt(j) == ch) {
counter++;
}
}
}
return counter;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…