@Test public void testSwitch() { byte b = 3; short s = 1; int i = 2; //byte、short會隱試的轉換為int類型,所以switch參數類型可以接收byte、short、int long l = 1; //而long類型不能隱式的轉換為int類型,所以switch參數類型不能接受long char c = '1'; String str = "hello"; //JDK1.7(包含1.7)之前的版本不支持char類型和String類型 switch(i) { case 1: { System.out.println("選擇一"); break; } case 2: { System.out.println("選擇二"); break; } default : { System.out.println("其他"); break; } } }