第四章第九题(给出字符的Unicode码)(Find the Unicode of a character)
-
*4.9(给出字符的Unicode码)编写一个程序,得到一个字符的输入,然后显示其Unicode值。
下面是一个运行示例:
Enter a character: E
The Unicode for the character E is 69*4.9(Find the Unicode of a character) Write a program that receives a character and displays its Unicode.
Here is a sample run:
Enter a character: E
The Unicode for the character E is 69 -
参考代码:
package chapter04;
import java.util.Scanner;
public class Code_09 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter a character: ");
String str = input.nextLine();
char character = str.charAt(0);
System.out.println("The Unicode for the character " + character + " is " + (int)character);
}
}
- 结果显示:
Enter a character: E
The Unicode for the character E is 69
Process finished with exit code 0