char 转 int 的两种方法

 



1 public class Hello {
2 public static void main(String[] args) {
3 char chNum = '9';
4 int a = (int)(chNum - '0');
5 int b = Character.getNumericValue(chNum);
6 System.out.println("a: "+a);
7 System.out.println("b: "+b);
8 }
9 }