根据输入1~12之间的数字,判断是春夏秋冬那个季节,要求使用方法定义四个季节. 用switch
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/19 04:07:46
根据输入1~12之间的数字,判断是春夏秋冬那个季节,要求使用方法定义四个季节. 用switch
输出的结果图是:
请输入月份:6
该季节为夏季
输出的结果图是:
请输入月份:6
该季节为夏季
public String whichSeason(int month) {
String season;
switch(month) {
case 1:
case 2;
case 3:
season = "该季节为春季";
break;
case 4:
case 5:
case 6:
season = "该季节为夏季";
break;
case 7:
case 8:
case 9:
season = "该季节为秋季";
break;
case 10:
case 11:
case 12:
season = "该季节为冬季";
break;
default:
season = "wrong month!";
}
return season;
}
String season;
switch(month) {
case 1:
case 2;
case 3:
season = "该季节为春季";
break;
case 4:
case 5:
case 6:
season = "该季节为夏季";
break;
case 7:
case 8:
case 9:
season = "该季节为秋季";
break;
case 10:
case 11:
case 12:
season = "该季节为冬季";
break;
default:
season = "wrong month!";
}
return season;
}