------- android培训、java培训、期待与您交流! ----------
//根据月份判断季节
class IfDemo
{
public static void main(String args[])
{
int x = 6;
if (x<1||x>12)
{
System.out.println("输入错误");
}
else if (x>=3&&x<=5)
{
System.out.println("春季");
}
else if (x>=6&&x<=8)
{
System.out.println("夏季");
}
else if (x>=9&&x<=11)
{
System.out.println("秋季");
}
else
System.out.println("冬季");
}
}
上面是if语句 接着是用switch语句
class SwitchDemo
{
public static void main(String args[])
{
int x = 6;
switch (x)
{
case 3:
case 4:
case 5:
System.out.println("春");
break;
case 6:
case 7:
case 8:
System.out.println("夏");
break;
case 9:
case 10:
case 11:
System.out.println("秋");
break;
case 12:
case 1:
case 2:
System.out.println("冬");
break;
}
}
}