本帖最后由 lzh2015 于 2015-6-3 13:11 编辑
class SwitchDemo{
public static void main(String[] args) {
int x=4;
switch (x){
case 1:
System.out.println("A");
case 2:
System.out.println("B");
case 3:
System.out.println("C");
case 4:
System.out.println("D");
case 5:
System.out.println("E");
default:
System.out.println("F");
}
}
}//打印的是 DEF
class SwitchDemo{ public static void main(String[] args) { int x=2; switch (x){ case 1: System.out.println("A"); case 2: System.out.println("B"); default: System.out.println("F"); case 3: System.out.println("C"); case 4: System.out.println("D"); case 5: System.out.println("E"); } } }//打印 BFCDE class SwitchDemo{ public static void main(String[] args) { int x=6; switch (x){ case 1: System.out.println("A"); case 2: System.out.println("B"); default: System.out.println("F"); case 3: System.out.println("C"); case 4: System.out.println("D"); case 5: System.out.println("E"); } } }//打印FCDE class SwitchDemo{ public static void main(String[] args) { int x=6; switch (4){ case 1: System.out.println("A"); case 2: System.out.println("B"); default: System.out.println("F"); case 3: System.out.println("C"); case 4: System.out.println("D"); case 5: System.out.println("E"); } } }//打印DE 总的来说,跟老师你讲没有break的的出入很大,望大牛们指点下,我已经被玩坏了!!
|