用switch判断月份的练习

时间:2021-12-02 07:20:16
import java.util.Scanner;

public class SwitchTest01
{
public static void main(String[] args)
{
System.out.println("请输入月份");
Scanner sc = new Scanner(System.in);
int month = sc.nextInt();
if (month >= 1 && month <= 12)
{
switch (month){
case 3:
case 4:
case 5:
System.out.println("春天");
break; case 6:
case 7:
case 8:
System.out.println("夏天");
break; case 9:
case 10:
case 11:
System.out.println("秋天");
break; case 12:
case 1:
case 2:
System.out.println("冬天");
break; }
}
else
{
System.out.println("请输入正确的月份");
}
}
}