public static int parseIntRange(String str,int minVal,int maxVal,boolean allowZero){
  try {
    if (str.charAt(0) == '+') {
      str=str.substring(1);
    }
    int val=Integer.parseInt(str);
    if (val < minVal || val > maxVal || (val == 0 && !allowZero)) {
      throw new InvalidFormatException("Integer value out of range: " + str);
    }
    return val;
  }
 catch (  NumberFormatException nfe) {
    throw new InvalidFormatException("Invalid integer value: " + str);
  }
}

public static int parseIntRange ( String str , int minVal , int maxVal , boolean allowZero ) { try { if ( str . charAt ( 0 ) == '+' ) { str = str . substring ( 1 ) ; } int val = Integer . parseInt ( str ) ; if ( val < minVal || val > maxVal || ( val == 0 && ! allowZero ) ) { throw new InvalidFormatException ( "Integer value out of range: " + str ) ; } return val ; } catch ( NumberFormatException nfe ) { throw new InvalidFormatException ( "Invalid integer value: " + str ) ; } }
parses an integer , with range - checking .
