条件语句的小练习
/根据输入数字打印季节。
public class TextSwitch{
public static void main(String[] args){
int x=4;
switch(x){
case 3:
case 4:
case 5:
System.out.println("Spring");
break;
case 6:
case 7:
case 8:
System.out.println("Summer");
break;
case 9:
case 10:
case 11:
System.out.println("Autumn");
break;
case 12:
case 1:
case 2:
System.out.println("Winter");
break;
default:
System.out.println("feifa");}
}
}
//需求:根据输入数字,打印相应星期。
/*public class TextIf{
public static void main(String[] args){
int a=2;
if(a==1)
System.out.println("Monday");
else if(a==2)
System.out.println("Tuesday");
else if(a==3)
System.out.println("Wednessday");
else if(a==4)
System.out.println("Thursday");
else if(a==5)
System.out.println("Friday");
else if(a==6)
System.out.println("Saturday");
else if(a==7)
System.out.println("Sunday");
else
System.out.println("nono");
}
}*/
//需求:根据输入数字,打印相应季节。
public class TextIf_2{
public static void main(String[] args){
int b=4;
if(b==3||b==4||b==5)
System.out.println("Spring");
else if(b==6||b==7||b==8)
System.out.println("Sunmmer");
else if(b==9||b==10||b==11)
System.out.println("Autumn");
else if(b==12||b==1||b==2)
System.out.println("Winter");
else
System.out.println("nono");
}
}
|
|