标签:value code pre string toggle data- out val ret
Switch
public class TestSwitchCase {
public static void main(String[] args) {
System.out.println(getValue(2));
}
public static int getValue(int i) {
int result = 0;
switch (i) {
default: System.out.println("default");
case 1:
result = result + i;
case 2:
result = result + i * 2;
case 3:
result = result + i * 3;
}
return result;
}
}
点击查看结果
10
public class TestSwitchCase2 {
public static void main(String[] args) {
byte a = 4;
switch (a) {
default:
System.out.println("default");
case 1:
System.out.println("A");
case 2:
System.out.println("B");
case 3:
System.out.println("C");
break;
case 4:
System.out.println("D");
}
}
}
点击查看结果
D
标签:value code pre string toggle data- out val ret
原文地址:https://www.cnblogs.com/hglibin/p/10092246.html