如何把 char ‘3’ 转为 int 3, 大家应该知道,不能直接转化,那样得到是‘3’的Ascii.
正确为:
public class CharToIntConverter {
public static void main(String[] args) {
char numChar = '3';
int intNum = numChar - '0';
System.out.println(numChar + ": " + intNum);
}
} 直接在numChar后面减去'0'即可,输出结果如下:3: 3
639

被折叠的 条评论
为什么被折叠?



