根据指定月份,打印该月份所属的季节
3,4,5春季
6,7,8夏季
9 10 11秋季
12 ,1,2 冬季
package day2;
import java.util.Scanner;
public class demo3 {
public static void main(String[] args) {
int i;
Scanner S = new Scanner(System.in);
System.out.println("请输入月份:");
i = S.nextInt();
switch (i) {
case 1:
case 2:
System.out.println("冬季");
break;
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:
System.out.println("冬季");
break;
default:
System.out.println("无效月份");
}
}
}
输出结果: