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 }
吾宁做一叶扁舟,始航于湖边,遨游于海上,浪迹于江中。