我正在尝试读取字符串的字符来获取数值。 String 卡号 = in.next();
int currentIndex = cardNumber.length() - 1;
while (currentIndex >= 0)
{
int smallValue;
smallValue = Character.getNumericValue(currentIndex);
当smallValue运行时,它没有给我这个数字。只是 -1
最佳答案
您应该使用Character.digit(),但您使用数组索引而不是该索引处的元素值来调用它。
关于java - 如果字符已经是java中的数字,则将字符转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5161483/