You're attempting to compare a string (Layout.ROWS[i]
) to a char
. You should iterate over the String
s in your array, and for each such String
iterate over the char
s that make it up. While this can be acheived with a while
loop, using for
loops would be much cleaner:
public static int count(char d) {
int sum = 0;
// Iterate over all the strings in Layout.ROWS:
for (String str : Layout.ROWS) {
// Iterate over the chars of the string:
for (int i = 0; i < str.length(); ++i) {
if (d == str.charAt(i)) {
++sum;
}
}
}
return sum;
}