Java Switch(String)

 1 package shb.java.test;
 2 /**
 3  * switch支持字符串
 4  * @Package:shb.java.test
 5  * @Description:
 6  * @author shaobn
 7  * @Date 2015-9-9上午8:55:41
 8  */
 9 public class test_3 {
10     public static void main(String[] args) {
11         System.out.println(testSwitchStr("jiangsu"));
12         System.out.println(testSwitchInt(2));
13         System.out.println(testSwitchChar('B'));
14     }
15     public static char testSwitchChar(char ch){
16         switch (ch) {
17         case 'A':
18             return 'A';
19         case 'B':
20             return 'B';
21         default:
22             return 'R';
23         }
24         
25     }
26     public static int testSwitchInt(int num){
27         switch (num) {
28         case 1:
29             return 1;
30         case 2:
31             return 2;
32         default:
33             return 0;
34         }
35     }
36     public static String testSwitchStr(String str){
37         switch (str) {
38         case "beijing":
39             return "hellobeijing";
40         case "jiangsu":
41             return "hellojiangsu";
42         default:
43             return "helloworld";
44         }
45         
46     }
47 }

 

posted @ 2015-09-09 08:56  邻家小书童  阅读(1900)  评论(0编辑  收藏  举报