本帖最后由 Akm 于 2013-5-24 17:28 编辑
- private static void test11() {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入一个数");
- int a =sc.nextInt();
- switch (a) {
- case 1:
- System.out.println("冬季");
- break;
- case 2:
- System.out.println("冬季");
- break;
- case 3:
- System.out.println("春季");
- break;
- case 4:
- System.out.println("春季");
- break;
- case 5:
- System.out.println("春季");
- break;
- case 6:
- System.out.println("夏季");
- break;
- case 7:
- System.out.println("夏季");
- break;
- case 8:
- System.out.println("夏季");
- break;
- case 9:
- System.out.println("秋季");
- break;
- case 10:
- System.out.println("秋季");
- break;
- case 11:
- System.out.println("秋季");
- break;
- case 12:
- System.out.println("冬季");
- break;
- default:
- System.out.println("输入错误");
- break;
- }
- }
复制代码 把上边的代码稍稍改下:- case 2:
- System.out.println("冬季");
- break;
- case 3:
- case 4:
- case 5:
- System.out.println("春季");
- break;
复制代码 这样两种写法,程序执行的效率一样吗?
|