1.根据输入1~12月的数字,判断是春夏秋冬那个季节..........................
方法一:
public class Season {
String season;//季节
public void show( int month) {
if(month>=1 && month<=3) {
season = "春季";
}else if(month>=4&& month<=6) {
season = "夏季";
}else if(month>=7 && month<=9) {
season = "秋季";
}else {
season = "冬季";
}
System.out.println(" ");
System.out.println("该季节是:"+season);
}
public static void main(String[] args) {
Season sea = new Season(); //创建新的对象
Scanner input = new Scanner(System.in);
System.out.print("请输入月份:");
int month = input.nextInt();
sea.show(month); //调用方法
}
}
方法二:
public class Season {
String season;//季节
int month; //月份
public void show() {
Scanner input = new Scanner(System.in);
boolean falg = true; //判断条件为真
while(falg) {
System.out.print("请输入月份:");
int month = input.nextInt();
switch(month) {
case 1:
case 2:
case 3:
season ="春季";
System.out.println("该季节是:"+season);
falg = false; //条件为假
break;
case 4:
case 5:
case 6:
season ="夏季";
System.out.println("该季节是:"+season);
falg = false;
break;
case 7:
case 8:
case 9:
season &#