Public class StringParesInteger {/*** @ param args */public static void main (String [] args) {// TODO Auto-generated method stubSystem. out. println (Integer. MIN_VALUE); System. out. println (Integer. MAX_VALUE/10); System. out. println (pareseInt ("=");}/** the main boundary condition * 1 is used in this question. whether the input string is null * 2. whether the first character string is (+,-) * 3. whether the characters contain invalid characters * 4. whether the input string exceeds the maximum Integer value (Integer. MAX_VALUE (1, 2147483647)/Integer. min _value (-2147483648) ** @ param data * @ return */public static int pareseInt (String data) {/** determine whether the passed string is null */if (data = null | data. length () = 0) {throw new NullPointerException ("data is null");} int index = 0; /***** // whether it is negative boolean isPositive = true; // The Critical Value int limit = 0; // retrieves the first char first = data of the string. charAt (0); // if (first = '-') {isPositive = false; index ++; // set the minimum Integer negative (-2147483648) limit =-Integer. MIN_VALUE;} // if (first = '+') {isPositive = true; // set the maximum positive value to (2147483647) limit = Integer. MAX_VALUE; index ++;} // set the Compare boundary value (214748364) int maxLimit = Integer. MAX_VALUE/10; int length = data. length (); int result = 0; while (index
'0' & ch <'9') {// first, judge whether the original value is greater than the comparison threshold. if (result> maxLimit) {throw new RuntimeException ("integer out of bounds ");} // determine whether the value of the current bit + the value of ch is the maximum integer if (result * 10> limit-(ch-'0') {System. out. println ("result -->" + (result * 10); System. out. println ("max ----->" + (Integer. MAX_VALUE); System. out. println ("result -->" + (Integer. MAX_VALUE-(ch-'0') + "ch =" + (ch-'0'); throw new RuntimeException ("array out of bounds s ");} index ++; result = result * 10 + (ch-'0');} else {throw n Ew RuntimeException ("not an integer");} // return isPositive? Result:-result ;}}