需求用java程度写出以下需求:一年有12个月,分属于春夏秋冬4个季节,键盘录入一个月份,请用程序实现判断该月份属于哪个季节,并输出。 春: 3、4、5 夏:6、7、8 秋: 9、10、11 冬: 1、2、12
时间: 2023-04-02 07:05:16 浏览: 168
以下是 Java 代码实现:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入月份:");
int month = scanner.nextInt();
String season;
switch (month) {
case 3:
case 4:
case 5:
season = "春";
break;
case 6:
case 7:
case 8:
season = "夏";
break;
case 9:
case 10:
case 11:
season = "秋";
break;
case 1:
case 2:
case 12:
season = "冬";
break;
default:
season = "输入错误";
break;
}
System.out.println("该月份属于" + season + "季节");
}
}
希望能够帮助到您!
阅读全文