View Single Post
  #2 (permalink)  
Old 08-01-2007, 09:18 PM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
According to this test/exploration your code should work. I wonder if the variable input could be something other than a char.
Code:
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); } } }
Reply With Quote