switch條件語句編程Invalid character constant錯誤
package com.imooc;
public class Demo1040602 {
public static void main(String[] args){
char detion='廣州';
switch(detion){
case "廣州":
System.out.println("坐長途汽車去");
break;
case "上海":
System.out.println("坐高鐵去");
break;
case "北京":
System.out.println("坐飛機去");
break;
default:
System.out.println("坐火箭去");
}
}
}
char detion='廣州'; ? ? ? 其中這一句是錯誤的
2016-01-11
char是可容納單個字符的數據類型,‘廣州’已經超出了char定義的范圍,故把char detion='廣州'改為String detion='廣州'即可。
2016-01-11
不一一回復了,你們的回答都很好。不回復的我已經贊了一個
2016-01-11
感謝各位的熱心解答
2016-01-11
jdk1.7以下的switch條件語句都不可以是String類型
2016-01-11
把char detion='廣州'改為String detion="廣州"
2016-01-11
char detion='廣州'; 換成 String detion = "廣州";
2016-01-11
一個漢字是兩個字節,'廣州'是四個字節,已經超出char的范圍