黑马程序员技术交流社区
标题:
if的练习
[打印本页]
作者:
wxw19910324
时间:
2016-1-2 15:53
标题:
if的练习
需求:根据用户指定的月份 打印该月份所属的季节。
3.4.5春季-6.7.8夏季-9.10.11秋季12.1.2冬季
class IfTest
{
public static void main(string[] args)
{
int x = 4;
if(x==3 | | x==4 | | x==5 )
System.out.println(x+"春季");
else if(x==6 | | x==7 | | x==8 )
System.out.println(x+"夏季");
else if(x==9 | | x==10| | x==11)
System.out.println(x+"秋季");
else if(x==12 | | x==1 | x==2)
System.out.println(x+"冬季");
else
System.out.println(x+"月份不存在");
}
}
作者:
qinrongchang
时间:
2016-1-2 21:48
你是来水经验的么?
作者:
雪中飞
时间:
2016-1-2 21:59
这个可以用switch语句更方便
作者:
houbofly
时间:
2016-1-2 22:20
厉害,加油,加油
作者:
小五哥
时间:
2016-1-2 22:22
加油加油
作者:
李冰
时间:
2016-1-2 22:39
666666666666
作者:
蔡泽杰
时间:
2016-1-2 23:12
雪中飞 发表于 2016-1-2 21:59
这个可以用switch语句更方便
都差不多拉,查表法更简单拉
作者:
s616622575
时间:
2016-1-2 23:15
发表这个干什么
作者:
n_Nie1991
时间:
2016-1-2 23:58
另一种写法
if(x>12 || x<0) {
System.out.println("您输入的月份不存在");
}
else if(x<=3 && x>=5) {
System.out.println("春季");
}
......
else {
System.out.println("冬季");
}
作者:
kegao
时间:
2016-1-3 00:13
代码追求浅显易懂,不错.
作者:
zhj806504628
时间:
2016-1-3 22:09
用switch吧!
作者:
wyb414
时间:
2016-1-3 22:38
厉害,加油,加油
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2