1 package com.demo; 2 3 import java.util.Scanner; 4 5 /* 6 * 題目:根據指定月份,列印該月份所屬的季節 7 * 8 * 春季:3 4 5 9 * 夏季:6 7 8 10 * 秋季:9 10 11 11 * 冬季:12 1 2 12 */ 1... ...
1 package com.demo;
2
3 import java.util.Scanner;
4
5 /*
6 * 題目:根據指定月份,列印該月份所屬的季節
7 *
8 * 春季:3 4 5
9 * 夏季:6 7 8
10 * 秋季:9 10 11
11 * 冬季:12 1 2
12 */
13
14 public class Season {
15 public static void main(String[] args) {
16
17 Scanner input = new Scanner(System.in);
18
19 System.out.print("請輸入月份(1-12):");
20 int month = input.nextInt();
21
22 switch (month) {
23 case 3:
24 case 4:
25 case 5:
26 System.out.println("春季");
27 break;
28 case 6:
29 case 7:
30 case 8:
31 System.out.println("夏季");
32 break;
33 case 9:
34 case 10:
35 case 11:
36 System.out.println("秋季");
37 break;
38 case 12:
39 case 1:
40 case 2:
41 System.out.println("冬季");
42 break;
43 default:
44 System.out.println("輸入有誤");
45 break;
46 }
47
48 }
49 }