java中char类型转换成int类型

版权声明: https://blog.csdn.net/RAVEEE/article/details/83409692

PlanA:

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

PlanB:

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

猜你喜欢

转载自blog.csdn.net/RAVEEE/article/details/83409692