| Code with Finding: |
class ArrayUtil {
/**
* Parses the string argument as if it was an int value and returns the
* result. Throws NumberFormatException if the string does not represent an
* int quantity. The second argument specifies the radix to use when parsing
* the value.
*
* @param chars a string representation of an int quantity.
* @param radix the base to use for conversion.
* @return int the value represented by the argument
* @throws NumberFormatException if the argument could not be parsed as an int quantity.
*/
public static int parseInt(char[] chars, int offset, int len, int radix)
throws NumberFormatException {
if (chars == null || radix < Character.MIN_RADIX
|| radix > Character.MAX_RADIX) {
throw new NumberFormatException();
}
int i = 0;
if (len == 0) {
throw new NumberFormatException("chars length is 0");
}
boolean negative = chars[offset + i] == '-';
if (negative && ++i == len) {
throw new NumberFormatException("can't convert to an int");
}
if (negative == true){
offset++;
len--;
}
return parse(chars, offset, len, radix, negative);
}
}
|