英文:
How to convert an integer to char in Java?
问题
我正在尝试在Java中获取整数的ASCII字符,但是在我尝试进行类型转换时它给我一个空字符。我正在执行:
int slowest = keyTimes.get(keyIndex).first;
其中,keyTimes是一个PairInts的列表,而PairInt包含两个整数,分别是first和second。然后我执行:
char ch = (char) slowest;
但是这并没有给我ASCII字符,并且输出是空白的。
英文:
I am trying to get the ASCII character of an integer in java, but it is giving me an empty char when I try to typecast it. I am doing:
int slowest = keyTimes.get(keyIndex).first;
where keyTimes is a List of PairInts and PairInt has 2 integers, first and second. I am then doing
char ch = (char) slowest;
but this does not give me the ASCII character, and prints blank.
答案1
得分: 1
int a=65;
char c=(char)a;
System.out.println(a);
这将输出 "A"。如果给定的数字没有对应的 ASCII 字符,也会输出黑色。因此,请检查您提供的整数。
英文:
int a=65;
char c=(char)a;
System.out.println(a);
This will give "A" as output. Also give black output if there is no ASCII character of given number. So please check the integer that you are providing.
答案2
得分: 0
如果打印 ch
会产生空格,则 slowest
的值将为 32,因为空格的 ASCII 值为 32。
您可以在 https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html 查看 ASCII 到字符的映射。
英文:
If printing ch
results in empty space, then slowest
value would be 32 as ASCII value of space is 32.
You can check the ASCII to character mapping at https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论