package xiafly;
import java.util.Scanner;
public class Testswitch {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.printf("请属于月份:");
int month = s.nextInt();
switch (month) {
case 1:
case 2:
case 3:
System.out.printf("春季");
break;
case 4:
case 5:
case 6:
System.out.printf("夏季");
break;
case 7:
case 8:
case 9:
System.out.printf("秋季");
break;
case 10:
case 11:
case 12:
System.out.printf("冬季");
break;
default:
System.out.printf("数字超出月份范围");
}
//switch增强语句
// switch (month) {
// case 1, 2, 3 -> System.out.printf("春季");
// case 4, 5, 6 -> System.out.printf("夏季");
// case 7, 8, 9 -> System.out.printf("秋季");
// case 10, 11, 12 -> System.out.printf("冬季");
// default -> System.out.printf("数字超出月份范围");
// }
}
}
运行结果:
请属于月份:6
夏季
Process finished with exit code 0