import java.util.Scanner;
public class Ex4_9 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("enter character");
String a = input.nextLine();
char ch = a.charAt(0);
if (a.length() == 1){
System.out.println("The character entered is " + ch);
System.out.println(" the Unicode for character " + ch + " " + ??);
}
else
System.out.println("complain about the number of characters.");
}
}
我希望能够输入E和java显示69.我需要填写什么?
答案 0 :(得分:0)
您想使用codePointAt
...
System.out.println(" the Unicode for character " + a + " " + a.codePointAt(0));
答案 1 :(得分:-1)
只需将ch
转换为int
即可获取其Unicode值,如
System.out.println(" the Unicode for character " + ch + " " + ((int) ch));
对于评论,这适用于任何 char
,但不适用于任何 Unicode代码点。但是,这个问题要求char
的解决方案,我的工作原理。 ch
初始化为a.charAt(0)
,无论如何都不会为代理人工作,所以我不会在downvote中看到任何理由。