测试代码发布到博客效果(Windows Live Writer发布)
public class SwitchCase {
/**
* 1、switch后面的表达式为常量表达式,类型只能是可以转化为int、enum(1.6+)、String(1.7+)的类型
* 2、可以转化为int类型的数据类型有:byte、short、int、char
* 3、boolean类型的数据类型推荐用if else,java中不支持使用
*
*
*/
public static int getAge(String name) {
int age = 0;
switch (name) {
case "张三":
age = 30;
break;
case "李四":
age = 40;
break;
default:
age = -1;
break;
}
return age;
}
public static void main(String[] args) {
int age = getAge("张三");
System.out.println(age);
}
}测试代码发布到博客效果(Windows Live Writer发布)
原文:http://www.cnblogs.com/cupOf/p/5541028.html