为什么从char中错误地减去?

Wil*_*tes 0 java math int char

所以这是我的代码:

public class charTest
{
  public static void main(String[] args)
  {
    String bigNum = ("789");
    char s1 = bigNum.charAt(0);
    System.out.println(s1);
    System.out.println(s1-1);
  }
}
Run Code Online (Sandbox Code Playgroud)

它在第一行打印7,然后在下一行打印出54,为什么?我有一个非常长的数字,我有一个字符串,我在其中单独引用个别数字.我刚做了减法测试,看它是否正常工作.任何见解?

Rei*_*eus 5

7(字符)的unicode点值是55.减去1给出54

第一个println语句使用一个char参数,而第二个语句使用int(int从一个char原因加宽到一个的减法int)

让6你可以做到

System.out.println(Character.getNumericValue(s1) - 1);
Run Code Online (Sandbox Code Playgroud)