問題是:在控制檯中顯示什麼?如何用''聲明int,爲什麼是'2'== 50?
我真的有一些理解上的問題。
下面是代碼:
public static void felda(){
char[] felda = {'2',0x31,48};
for (int i = 0; i< felda.length; i++){
System.out.println(" : " + felda[i]);
}
System.out.println();
}
public static void feldb(){
int[] feldb = {'2',0x31,48};
for (int i = 0; i< feldb.length; i++){
System.out.println(" : " + feldb[i]);
}
System.out.println();
}
public static void feldc(){
int [] feldc = {'2',0x31,48};
for (int i = 0; i< feldc.length; i++){
System.out.println(" : " + (char) feldc[i]);
}
System.out.println();
}
所以,如果我在解決方案上運行是:
: 2
: 1
: 0
: 50
: 49
: 48
: 2
: 1
: 0
所以我不明白是怎麼回事,甚至可能有「一個int definded 」。 我發現它很混亂如何int feldb = '2'
結果是50和int feldb = 0x31結果是49 ..大壩這一切都很混亂。我希望有人能夠啓發我。
編輯:爲什麼char feldc = 48;
導致0?
HTTP://www.asciitable .com/ – QuakeCore
http://www.ascii-code.com/ –
相關:http://stackoverflow.com/questions/32051600/char-to-int-conversion –