public class Solution {
public static int StringConvertToInt(String num) throws Exception {
char[] ch = num.toCharArray();
int i = 0, value = 0;
while (i < ch.length)
{
if (ch[i] == ' ') {
i++; continue;
}
if (ch[i] < '0' || ch[i] > '9')
throw new Exception("node number");
value = value * 10 + (ch[i] - '0');
i++;
}
return value;
}
public static void main(String[] args) throws Exception {
String str = "123 456";
System.out.println(StringConvertToInt(str));
}
}
输出:
123456