The Exception in the thread "main" Java. Lang. A NumberFormatException: For input string: "9999999991"
The at Java. The base/Java. Lang. A NumberFormatException. ForInputString (68). A NumberFormatException Java:
The at Java. The base/Java. Lang. Integer. The parseInt (Integer. Java: 652)
The at Java. The base/Java. Lang. Integer. The parseInt (Integer. Java: 770)
The at cn. Day11. Solution. The reverse (18) Solution. Java:
The at cn. Day11. Main. The main (14). The main Java:
Code:
Package cn. Day11;
//1999999999
//1534236469
Public class main {
Public static void main (String [] args) {
Solution d=new Solution ();
Int I=d.r everse (1999999);
System.out.println(i);
Int j=1534236469;
Int k=1999999999;
System. Out.println (k> Integer. MAX_VALUE);
}
}
The class Solution {
Public int reverse (int x) {
Int fuhao=1;
String s=String. The valueOf (x);
StringBuffer sb=new StringBuffer (s);
If (sb. CharAt (0)=='-') {
Fuhao=1;
Sb. DeleteCharAt (0);
} String ss=sb. Reverse (). The toString ();
String SSS="1999999999";
System. The out. Println (SSS) length ());
System. The out. Println (ss) length ());
Int result=Integer. ParseInt (ss. The trim ());
If (result> Integer. MAX_VALUE | | result
}
return result;
}
}
Description: the fault is not an integer. The parseint (), when the Numbers in parentheses is small, such as ss=12345 is not an error, when in parentheses is SSS parseint () of the largest number, not an error, but the ss=1999999999 (SSS) and an error, is this why? Bosses give directions
CodePudding user response:
Sb. Reverse () this step is to turn, more than the maximum of type int, so abnormal conversionCodePudding user response: