0
点赞
收藏
分享

微信扫一扫

case的穿透优化

import java.util.Scanner;

public class penetrate {
    public static void main(String[] args) {

    }
    public static void switchTest1(){
        //键盘录入一个数值,其中1-5表示工作日,6-7表示休息日
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入:");
        int week=sc.nextInt();
        switch (week){
            //第一种
//            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;
//            default:
//                System.out.println("你的输入有误");
//                break;
            //第二种
//            case 1:
//            case 2:
//            case 3:
//            case 4:
//            case 5:
//                System.out.println("工作日");
//                break;
//            case 6:
//            case 7:
//                System.out.println("休息日");
//                break;
//            default:
//                System.out.println("你的输入有误");
//                break;
            //第三种
//            case 1,2,3,4,5:
//                System.out.println("工作日");
//                break;
//            case 6,7:
//                System.out.println("休息日");
//                break;
//            default:
//                System.out.println("你的输入有误");
//                break;
            //第四种
            case 1,2,3,4,5-> System.out.println("工作日");
            case 6,7->System.out.println("休息日");
            default->System.out.println("你的输入有误");
        }

    }
}

举报

相关推荐

0 条评论