2017-08-14 20 views

回答

4

int0相當於一個ASCII NUL(這恰好是在許多語言中String終止字符,但Java是不是其中之一)。這個問題(在Eclipse中也是可重現的)在於控制檯。

char ch1 = '\0'; 
System.out.printf("the value of the char is: %c ends%n", ch1); 
1

您正在爲char指定0,它應該用單引號引起來。試試這個:

ch2 = 'E'; 
ch1 = '0'; 
System.out.print("the value of the ch1 and ch2 is:"); 
System.out.println(ch1 + " " + ch2 + " ends"); 

希望這會有所幫助。

+0

你可以用UNICODE的範圍內的任何int值初始化char! – Hrcule