class SwitchDemo { public static void main(String[] args) { int x=8; switch(x) { case 0: System.out.println("0成功"); case 1: System.out.println("1成功"); case 2: System.out.println("2成功"); case 3: System.out.println("3成功"); case 4: System.out.println("4成功"); case 5: System.out.println("5成功"); case 6: System.out.println("6成功"); case 7: System.out.println("7成功"); case 8: System.out.println("08成功"); default: System.out.println("都失败"); } } }运行结果:08成功 都失败 class SwitchDemo { public static void main(String[] args) { int x=8; switch(x) { case 0: System.out.println("0成功"); case 1: System.out.println("1成功"); case 2: System.out.println("2成功"); case 3: System.out.println("3成功"); case 4: System.out.println("4成功"); case 5: System.out.println("5成功"); case 6: System.out.println("6成功"); case 7: System.out.println("7成功"); default: System.out.println("都失败"); } } }运行结果:都失败 class SwitchDemo { public static void main(String[] args) { int x=8; switch(x) { case 0: System.out.println("0成功"); case 1: System.out.println("1成功"); case 2: System.out.println("2成功"); case 3: System.out.println("3成功"); case 4: System.out.println("4成功"); case 8: System.out.println("08成功"); case 5: System.out.println("5成功"); case 6: System.out.println("6成功"); case 7: System.out.println("7成功"); default: System.out.println("都失败"); } } }运行结果:08成功 5成功 6成功 7成功 都失败 class SwitchDemo { public static void main(String[] args) { int x=8; switch(x) { case 0: System.out.println("0成功"); case 1: System.out.println("1成功"); case 2: System.out.println("2成功"); case 3: System.out.println("3成功"); case 4: System.out.println("4成功"); case 8: System.out.println("08成功"); break; case 5: System.out.println("5成功"); case 6: System.out.println("6成功"); case 7: System.out.println("7成功"); default: System.out.println("都失败"); } } }运行结果:08成功 class SwitchDemo { public static void main(String[] args) { int x=8; switch(x) { case 0: System.out.println("0成功"); case 1: System.out.println("1成功"); case 2: System.out.println("2成功"); case 3: System.out.println("3成功"); case 4: System.out.println("4成功"); case 8: System.out.println("08成功"); case 5: System.out.println("5成功"); case 6: System.out.println("6成功"); break; case 7: System.out.println("7成功"); default: System.out.println("都失败"); } } }运行结果:08成功 5成功 6成功 class SwitchDemo { public static void main(String[] args) { int x=8; switch(x) { default: System.out.println("都失败"); case 0: System.out.println("0成功"); case 1: System.out.println("1成功"); case 2: System.out.println("2成功"); case 3: System.out.println("3成功"); case 4: System.out.println("4成功"); case 8: System.out.println("08成功"); case 5: System.out.println("5成功"); case 6: System.out.println("6成功"); break; case 7: System.out.println("7成功"); } } }运行结果:08成功 5成功 6成功 class SwitchDemo { public static void main(String[] args) { int x=8; switch(x) { default: System.out.println("都失败"); case 0: System.out.println("0成功"); case 1: System.out.println("1成功"); case 2: System.out.println("2成功"); case 3: System.out.println("3成功"); case 4: System.out.println("4成功"); case 5: System.out.println("5成功"); case 6: System.out.println("6成功"); break; case 7: System.out.println("7成功"); } } }运行结果:都失败 0成功 1成功 2成功 3成功 4成功 最后再加一句,JDK1.7之后增加的字符串类型也和上面一样哦。
|