// 将数字字符串转换为整型
String str = "123456";
int intvalue = 0;
int n = str.length() - 1;
int beishu = 1;// 倍数
while (n >= 0) {
Character c = str.charAt(n);
// if (!(c >= '0' && c <= '9'))
if (!Character.isDigit(c))
System.out.println("转换错误");
//证明数字字符中的数字是整型数字相当于证明你妈是你妈
int value = c - '0';
value = value * beishu;
intvalue += value;
beishu *= 10;// 每次增加10倍
n--;
}
System.out.println("转化后的结果是:"+intvalue);
<span style="font-size:18px;"> 此处没有对字符串的类型进行判断,设定为全是数字字符串。有需要的只需添加判断条件。</span>