我制作了一个小代码块,其目标是尝试将数字的所有数字存储到数组中。例如,数字“123”将存储为 {1,2,3}。一切似乎都运行良好,除非数字的长度大于10。是我的方法有问题吗?确切的错误消息是
线程“main” java.lang.NumberFormatException 中的异常:对于输入字符串:“1202020202020202020” at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Integer.parseInt(Integer.java:652) at java.base/java.lang.Integer.parseInt(Integer.java:770) at test.main(test.java:8)
public class test {
public static void main(String[] args){
//This block of code parses the zipcode and stores each number it has into an array. It also fetches the length, which is used later.
String input = args[0];
int length = input.length();
int zipcode = Integer.parseInt(args[0]);
int[] digits = new int[length];
for(int i = 0; i < length ; i++){
digits[i] = zipcode % 10;
zipcode = zipcode /10;
}
}
}
慕斯王
相关分类