有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何从字符串传递到字符

我有以下资料:

String a = "\u0043";

我知道这是一个Unicode字符,我想获得它的ASCII值
这是我想做的一个例子:

String A = "A";

int ascii = 65;

或:

String A = "\u0043";

int ascii = 67;

共 (1) 个答案

  1. # 1 楼答案

    String A ="\u0043"; //Letter C
    int c = A.charAt(0);
    System.out.println(c); //Prints 67
            
    String B = "A"; //Letter A
    int a = B.charAt(0);
    System.out.println(a); //Prints 65