开发者

How to write a program that receives an ASCII code and display its character?

开发者 https://www.devze.com 2022-12-19 20:58 出处:网络
I\'m new with Java and just learning... but how would you write a program that receives an ASCII code and displays its character. Fo开发者_运维知识库r example, if the user enters 97,the program displa

I'm new with Java and just learning... but how would you write a program that receives an ASCII code and displays its character. Fo开发者_运维知识库r example, if the user enters 97,the program displays character a.


int i = 97;
char c = (char)i; //c will contain 'a'


Use Integer.parseInt(string) to turn that 97 into an integer. You can then explicitly cast that into a char:

String asciiCode = "97";
(char)Integer.parseInt(asciiCode);
0

精彩评论

暂无评论...
验证码 换一张
取 消