为什么串联的字符会打印数字? [英] Why does concatenated characters print a number?
本文介绍了为什么串联的字符会打印数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下课程:
public class Go {
public static void main(String args[]) {
System.out.println("G" + "o");
System.out.println('G' + 'o');
}
}
这是编译结果;
Go
182
为什么我的输出中包含数字?
Why my output contain a number?
推荐答案
在第二种情况下,它添加了 unicode 代码,两个字符(G-71和o-111)并打印总和.这是因为 char
被视为数字类型,因此在这种情况下, +
运算符是通常的求和.
In the second case it adds the unicode codes of the two characters (G - 71 and o - 111) and prints the sum. This is because char
is considered as a numeric type, so the +
operator is the usual summation in this case.
这篇关于为什么串联的字符会打印数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文