//需求: 输入月份,判断季节.
import java.util.Scanner;
class Month {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入月份1-12:");
int op = sc.nextInt();
/*if (op > 12 && op <1){
System.out.println("您输入的月份有误!");
}else if (op >= 3 && op <= 5){
System.out.println(op + "月是春季");
}else if (op >= 6 && op <= 8){
System.out.println(op + "月是夏季");
}else if (op >= 9 && op <= 11){
System.out.println(op + "月是秋季");
}else {
System.out.println(op + "月是冬季");
}*/
switch (op){
case 1:
case 2:
case 12:
System.out.println(op + "月是冬季");
break ;
case 3:
case 4:
case 5:
System.out.println(op + "月是春季");
break ;
case 6:
case 7:
case 8:
System.out.println(op + "月是夏季");
break ;
case 9:
case 10:
case 11:
System.out.println(op + "月是秋季");
break ;
default :
System.out.println("您输入的月份有误,范围1-12");
break ;
}
}
}
|
|