为什么等式返回它的答案?

问题描述 投票:0回答:2

我对为什么返回1感到困惑;

(char)('0' + 11) = ;为什么?

下面的完整代码,结尾为1;

 char[] ending;
       char a = (char)('0' + 11/10); 
        ending = new char[]{a, (char)('0' + 11)};
        System.out.println(ending);
java
2个回答
2
投票
  • '0'的字符值是48。
  • 48 + 11 = 59
  • 59的字符值是';'

您可以在互联网上的任何ASCII字符集中以整数值检查char值。

在Java中,char可以用作intshortbytelong,其值介于0到65535之间,无需任何强制转换。

Java char is also an int?中找到了更好的解释


1
投票

您正在为变量a分配'1'。 '0'+ 11/10 =>'0'+ 1您正在为结尾分配两个字母的字符串。 Le第一个字母为('1'),第二个字母为半冒号。 ('0'+ 11)。

© www.soinside.com 2019 - 2024. All rights reserved.