java从键盘输入某月份,判断此月份属于哪一个季节。 春季:2、3、4月份 夏季:5、6、5月份 秋秀:8,9、10月份 冬季:11、12、1月份
时间: 2023-05-21 18:03:10 浏览: 99
可以使用以下代码实现:
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 2:
case 3:
case 4:
season = "春季";
break;
case 5:
case 6:
case 7:
season = "夏季";
break;
case 8:
case 9:
case 10:
season = "秋季";
break;
case 11:
case 12:
case 1:
season = "冬季";
break;
default:
season = "输入月份有误!";
}
System.out.println(season);
}
}
阅读全文