Java编程语言基础 第三章 季节if用法

package cn.save;

import java.util.Scanner;

public class Dome2 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("请输入数字:");
int month = input.nextInt();
String season ="";

if(month>12 || month<1){//保障输入的是1-12月
System.out.println("输出月份不合理:");

}else {
//冬季 11 12 1 春季 2 3 4 夏季 5 6 7 秋季 8 9 10
if(month==1 || month>=11){
season ="冬天";
}else if(month<4 && month>=2){
season ="春天";
}else if(month<8 && month>=4){
season ="夏天";
}else if(month<11 && month>=8){
season ="秋天";
}
System.out.println(season);
}
}
}

posted on 2018-07-18 13:44  冷硕  阅读(337)  评论(0编辑  收藏  举报

导航