/**
*
* @author Tuerlechat,
* 根据用户选择的月份,输出对应的季节,季节使用枚举定义。
*
*/
public class Lxt1 {
//定个枚举类
enum Seasons {
Spring,Summer,autunm,winter
}
/**
*
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("请选择一个月份:");
int month = sc.nextInt();
switch (month) {
case 1:
case 2:
case 3:
System.out.println(month + "月是春天。");
break;
case 4:
case 5:
case 6:
System.out.println(month + "月是夏天。");
break;
case 7:
case 8:
case 9:
System.out.println(month + "月是秋天。");
break;
case 10:
case 11:
case 12:
System.out.println(month + "月是冬天。");
break;
default:
System.out.println("输入值错误,应输入正确的月份。");
}
}
}
【Java学习系列小例子】Java高级之根据用户选择的月份,输出对应的季节,季节使用枚举定义。
于 2022-08-28 14:25:56 首次发布