所以我在读这个:
10011011001;0110,1001,1001,0,10,11
并在其上运行此代码:
String[] parts = line.split(";");
System.out.println("Part 1 = " + parts[0]);
System.out.println("Part 2 = " + parts[1]);
System.out.println(isNumeric(parts[0]));
int original = Integer.parseInt(parts[0]);
System.out.println("Original = " + original);
该isNumeric
方法是我为调试而编写的。
public static boolean isNumeric(String str) {
for (char c : str.toCharArray()) {
if (!Character.isDigit(c)) {
return false;
}
}
return true;
}
输出:
Line = 10011011001;0110,1001,1001,0,10,11
Part 1 = 10011011001
Part 2 = 0110,1001,1001,0,10,11
true
Exception in thread "main" java.lang.NumberFormatException: For input string: "10011011001"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at str_substitution.main(str_substitution.java:45)
不知道为什么会出现这个异常,显然字符串是数字的,并且有效。