写一串Java代码:根据用于指定月份,打印输出该月份所属的季节,春季:3,4,5月;夏季:6,7,8月;秋季:9,10,11;冬季:12,1,2。
时间: 2024-05-27 22:11:33 浏览: 44
import java.util.Scanner;
public class Season {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入月份:");
int month = input.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("输入有误,请重新输入!");
break;
}
}
}
阅读全文