天天看點

根據用指定的月份,列印該月所屬的季節(switch)3,4,5 春季 6,7,8 為夏季 9,10,11 秋季 12,1,2冬季

源碼如下:

        Scanner sv = new Scanner(System.in);

        System.out.print("請輸入月份(1-12):");

        int c = sv.nextInt();

        switch (c) {

        case 1:

        case 2:

        case 12:

            System.out.println(c + "月是冬季!");

            break;

        case 3:

        case 4:

        case 5:

            System.out.println(c + "月是春季!");

            break;

        case 6:

        case 7:

        case 8:

            System.out.println(c + "月是夏季!");

            break;

        case 9:

        case 10:

        case 11:

            System.out.println(c + "月是秋季!");

            break;

        default:

            System.out.println(c + "是什麼呀!你的輸入有誤!要輸入1-12的數字喲!");

            sv.nextLine();

        }