为什么我在添加字符时会得到一个数字? [英] Why do I get a number when I add chars?

查看:35
本文介绍了为什么我在添加字符时会得到一个数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经决定将两个字符加在一起,并给了我一个数字.这是代码:

I once decided to add two chars together, and it gave me a number. Here's the code:

class Main {
  public static void main(String[] args) {
    System.out.println('a'+'b');
  }
}

输出: 195 .

我已经搜索了很多地方,但是我仍然不知道为什么 char + char = int .有人可以向我解释吗?

I've searched in a lot of places, but I still couldn't figure out why a char + char = int. Can someone explain this to me?

注意:这不是重复!!另一个问题是询问添加的char的数据类型.这个问题问为什么会这样.这些是具有不同答案的不同问题!

NOTE: THIS IS NOT A DUPLICATE!! The other question is asking the data type of an added char. This question asks why this happens. Those are DIFFERENT QUESTIONS WITH DIFFERENT ANSWERS!

推荐答案

您要添加其ASCII值:

You're adding their ASCII values:

'a'+'b' = 97+98 = 195

这篇关于为什么我在添加字符时会得到一个数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆