Java-用switch判断季节
import java.util.*;
class Demo3
{
public static void main(String[] args)
{
//需求 :输入一个月份 ,判断月份属于哪一个季节 :春天:3,4,5
//夏天 :6,7,8 ,秋天:9,10,11 冬天:12,1,2
System.out.println("请输入一个月份:");
//Scanner 输入函数
//使用Scanner 需要导入包 :java.util.*
Scanner sca = new Scanner(System.in);
int num = sca.nextInt();
switch(num){
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;
default:
System.out.println("你来至火星");
break;
}
}
}