Adding char and int(添加 char 和 int)
问题描述
据我了解,char 是单个字符,即字母、数字、标点符号、制表符、空格或类似的东西.因此,当我这样做时:
To my understanding a char is a single character, that is a letter, a digit, a punctuation mark, a tab, a space or something similar. And therefore when I do:
char c = '1';
System.out.println(c);
输出 1 正是我所期望的.那么为什么当我这样做时:
The output 1 was exactly what I expected. So why is it that when I do this:
int a = 1;
char c = '1';
int ans = a + c;
System.out.println(ans);
我最终得到输出 50?
推荐答案
你得到它是因为它添加了 ASCII 值 字符.您必须先将其转换为 int.
You're getting that because it's adding the ASCII value of the char. You must convert it to an int first.
这篇关于添加 char 和 int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:添加 char 和 int


基础教程推荐
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 大摇大摆的枚举 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01