输入月份判断是什么季节java
时间: 2023-05-21 13:03:19 浏览: 127
可以使用以下代码来判断季节:
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();
String season = "";
switch (month) {
case 12:
case 1:
case 2:
season = "冬季";
break;
case 3:
case 4:
case 5:
season = "春季";
break;
case 6:
case 7:
case 8:
season = "夏季";
break;
case 9:
case 10:
case 11:
season = "秋季";
break;
default:
System.out.println("输入的月份有误!");
return;
}
System.out.println(month + "月份是" + season);
}
}
这个程序可以根据输入的月份来判断是哪个季节。如果输入的月份不在1-12之间,则会提示输入有误。
阅读全文