package work1;
import java.util.Scanner;
public class Test {
enum Season{
spring,summer,autumn,winter;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("请输入月份:");
int num=sc.nextInt();
if(1<=num&&num<=3){
Season season=Season.spring;
System.out.println("对应的季节为春天");
} else if (4<=num&&num<=6) {
Season season=Season.summer;
System.out.println("对应的季节为夏天");
} else if (7<=num&&num<=9) {
Season season=Season.autumn;
System.out.println("对应的季节为秋天");
}else if (10<=num&&num<=12) {
Season season=Season.winter;
System.out.println("对应的季节为冬天");
}
else {
System.out.println("输入有误");
}
}
}
根据用户选择的月份,输出对应的季节,季节使用枚举定义。
最新推荐文章于 2024-11-09 12:43:52 发布