Java中char类型转换成int类型的方法

Java中char类型转换成int类型的两种方法

方法一:

 

char ch = '1'; if (Character.isDigit(ch)){ // 判断是否是数字 int num = Integer.parseInt(String.valueOf(ch)); System.out.println(num); }

方法二:

 

char ch = '1'; if (Character.isDigit(ch)){ // 判断是否是数字 int num = (int)ch - (int)('0'); System.out.println(num); }

猜你喜欢

转载自blog.csdn.net/qq_18287147/article/details/106887662