Switch-case语句的使用

根据用于指定月份,打印该月份所属的季节。其中3,4,5为春季,6,7,8为夏季,9,10,11为秋季,12,1,2为冬季。

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入指定的月份:");
        int month=sc.nextInt();
        switch(month){
            case 3 :
            case 4 :
            case 5 :
                System.out.println("春季");
                break;
            case 6 :
            case 7 :
            case 8 :
                System.out.println("夏季");
                break;
            case 9 :
            case 10 :
            case 11 :
                System.out.println("秋季");
                break;
            case 12 :
            case 1 :
            case 2 :
                System.out.println("冬季");
                break;
            default :
                System.out.println("输入的月份不存在,请重新输入。");
        }

    }
}
posted @ 2022-06-15 12:49  湖里小鲨鱼  阅读(457)  评论(0)    收藏  举报