Home > Back-end >  Save the children!
Save the children!

Time:04-24

Error:
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 | | resultreturn 0;
}
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 conversion

CodePudding user response:

reference 1/f, seven of the world, I'll take ninety-nine response:
sb. The reverse () this step is to turn, more than the maximum of type int, so abnormal conversion

No integer maximum range is two billion one hundred million, is a maximum of 1999999999, more than range

CodePudding user response:

refer to the second floor m0_57091160 response:
Quote: reference 1/f, seven of the world, I'll take ninety-nine response:
sb. The reverse () this step is to turn, more than the maximum of type int, so abnormal conversion

Maximum range is two billion one hundred million, no integer range is a maximum of 1999999999, there is no more than

The number 9999999991 is not more than the maximum?

CodePudding user response:

reference 3 floor seven of the world, I'll take ninety-nine response:
Quote: refer to the second floor m0_57091160 response:
Quote: reference 1/f, seven of the world, I'll take ninety-nine response:
sb. The reverse () this step is to turn, more than the maximum of type int, so abnormal conversion

Maximum range is two billion one hundred million, no integer range is a maximum of 1999999999, there is no more than

The number 9999999991 is not more than the maximum?

Ha ha, want a noon, waking up to see
  • Related