您的位置:首页 > 运维架构 > Linux

Linux运维系统工程师与java基础学习系列-5

2014-08-15 11:09 218 查看
Java天生骄傲系列-5 程序流程控制(续):
选择结构
switch语句 格式: Switch(表达式) { case取值1: 执行语句; break; case取值2: 执行语句; break; …… default: 执行语句; break; }
牛刀小试1:

package test.myeclipse;
publicclass test1 {

publicstaticvoid main(String[] args) {
int x=3;
switch(x)
{
case 1:
System.out.println('1');
break;
case 2:
System.out.println('2');
break;
case 3:
System.out.println('3');
break;
default:
System.out.print("error");
break;

}

}

}运行结果:3
牛刀小试2:
package test.myeclipse;
publicclass test1 {
publicstaticvoid main(String[] args) {
int x=3;
switch(x)
{
case 1:
System.out.println('1');
break;
case 2:
System.out.println('2');
break;
case 5:
System.out.println('3');
break;
default:
System.out.print("error");
break;

}

}

}
运行结果:error

未完待续!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux Java 运维技术