我在eclipse中有这个代码:
String A = String.valueOf(a);
String B = String.valueOf(b);
String C = String.valueOf(c);
String D = String.valueOf(d);
String E = String.valueOf(e);
String F = String.valueOf(f);
String G = String.valueOf(g);
String H = String.valueOf(h);
String I = String.valueOf(i);
String J = String.valueOf(j);
String K = String.valueOf(k);
String rawpassword = A+B+C+D+E+F+G+H+I+J+K;
int password = Integer.parseInt(rawpassword);
System.out.println(password);
它给了我这个错误
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:495)
at java.lang.Integer.parseInt(Integer.java:527)
at com.jakibah.codegenerator.Main.Generate(Main.java:65)
at com.jakibah.codegenerator.Main.run(Main.java:24)
at java.lang.Thread.run(Thread.java:745)
但我不明白为什么。 有人能帮助我吗?
答案 0 :(得分:3)
String A = String.valueOf(10);
String B = String.valueOf(10);
String C = String.valueOf(10);
String D = String.valueOf(10);
String E = String.valueOf(10);
String F = String.valueOf(10);
String G = String.valueOf(10);
String H = String.valueOf(10);
String I = String.valueOf(10);
String J = String.valueOf(10);
String K = String.valueOf(10);
String codestring = A+B+C+D+E+F+G+H+I+J+K;
BigInteger bigInteger = new BigInteger(codestring);
System.out.println(bigInteger.max(bigInteger));
答案 1 :(得分:1)
如果参数不是可解析的parseInt(String s)
,则NumberFormatException
方法会抛出Integer
。
确保传递给该方法的String
为Number
且介于-2^31
和2^31 - 1
答案 2 :(得分:0)