最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
jsp switch开关语句用法
时间:2011-05-06 编辑:简简单单 来源:一聚教程网
switch 开关声明允许你选择一组语句中运行的一种选择,基于代码的返回值一个表达式。
switch (expression) {
case value_1 :statement (s);
break;
case value_2 :
statement (s);
break;
.
.
.
case value_n :
statement (s);
break;
default:
statement (s);
}
实例测试
public class mainclass {
public static void main(string[] args) {
int i = 1;
switch (i) {
case 1 :
system.out.println("one.");
break;
case 2 :
system.out.println("two.");
break;
case 3 :
system.out.println("three.");
break;
default:
system.out.println("you did not enter a valid value.");
}
}
方法二 字符
public class mainclass {
public static void main(string[] args) {
char yesno = 'n';switch(yesno) {
case 'n': case 'n':
system.out.println("no selected");
break;
case 'y': case 'y':
system.out.println("yes selected");
break;
}
}
}
方法三
public class main {
public static void main(string[] args) {
int i = 0;
switch (i) {case 0:
system.out.println("i is 0");
case 1:
system.out.println("i is 1");
case 2:
system.out.println("i is 2");
default:
system.out.println("free flowing switch example!");
}
}
}
/*
i is 0
i is 1
i is 2
free flowing switch example!
*/
-
上一个: 利用lastIndexOf字符查找方法
-
下一个: java文件操作zip压缩文件读取写操作
相关文章
- jsp switch语句的用法 06-07
- js switch 教程 03-31
- SpringBoot测试配置属性与web启动环境解析 10-24
- vue中将el-switch值true、false改为number类型的1和0解析 10-24
- Vue中的路由配置项meta使用解读 10-24
- SpringBoot自定义bean绑定解析 10-24