switch
JDK1.6 只能使用数字
JDK1.7 开始可以使用字符串
static Object get(String key) {
switch (key) {
case "1":
System.out.println("1111");
break;
case "222":
System.out.println("2222");
break;
}
return null;
}
C语言中的switch
#include <stdio.h> int main() { int value = 1; switch (value) { case 1: printf("1\n"); default: printf("default\n"); case 2: printf("2\n"); break; } }
mutian@mutian:~/test/test$ ./a.out 1 default 2
#include <stdio.h> int main() { int value = 5; switch (value) { case 1: printf("1\n"); default: printf("default\n"); case 2: printf("2\n"); break; } }
mutian@mutian:~/test/test$ ./a.out default 2

浙公网安备 33010602011771号