您的位置:首页 > 编程语言 > Java开发

Java Switch(String)

2015-09-09 08:56 465 查看
package shb.java.test;
/**
* switch支持字符串
* @Package:shb.java.test
* @Description:
* @author shaobn
* @Date 2015-9-9上午8:55:41
*/
public class test_3 {
public static void main(String[] args) {
System.out.println(testSwitchStr("jiangsu"));
System.out.println(testSwitchInt(2));
System.out.println(testSwitchChar('B'));
}
public static char testSwitchChar(char ch){
switch (ch) {
case 'A':
return 'A';
case 'B':
return 'B';
default:
return 'R';
}

}
public static int testSwitchInt(int num){
switch (num) {
case 1:
return 1;
case 2:
return 2;
default:
return 0;
}
}
public static String testSwitchStr(String str){
switch (str) {
case "beijing":
return "hellobeijing";
case "jiangsu":
return "hellojiangsu";
default:
return "helloworld";
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: