2017-08-14 48 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