According to this test/exploration your code should work. I wonder if the variable
input could be something other than a
char.
public class Test {
public static void main(String[] args) {
char[] chars = { 'a', 'b', 'c', 'd' };
explore(chars);
String s = "";
for(int j = 0; j < chars.length; j++) {
char c = chars[j];
switch(c) {
case 'a': // both seem to
// case 97: // work okay
s = "a";
break;
case 'b':
// case 98:
s = "b";
break;
case 'c':
// case 99:
s = "c";
break;
case 'd':
// case 100:
s = "d";
break;
default:
s = "default";
}
System.out.printf("j = %d s = %s%n", j, s);
}
}
private static void explore(char[] chars) {
for(int j = 0; j < chars.length; j++) {
char c = chars[j];
int n = (int)chars[j];
System.out.printf("j = %d c = %s n = %3d c == n = %b%n",
j, c, n, c == n);
}
}
}