黑马学习笔记——switch

来源:互联网 发布:ubuntu 12.04 编辑:程序博客网 时间:2024/06/06 17:20
/*test switch snatex
solution:
1.creat a varible to store the input of user ;
2.use "switch" determine the number 
*/


class switchtest 
{
public static void main(String[] args) 
{
int x=3;//the input number
switch(x)
{
//if x==1.2.12,output spring
case 12:
case 1:
case 2:
System.out.println(x+"is spring");
break;
//if x==3.4.5,output summer
case 3:
case 4:
case 5:
System.out.println(x+"is summer");
break;
//if x==6.7.8,output autum
case 7:
case 6:
case 8:
System.out.println(x+"is autum");
break;
//if x==9.10.11,output winter
case 9:
case 10:
case 11:
System.out.println(x+"is winter");
break;
//and if you send a illegal number
default:
System.out.println(x+"is error");
}
}


}