/** * * @param code * @return 如果返回值是一个大于0的整数 如果返回-2表示所传的参数为空 ,如果返回值是-1 表示字符串中含有非数字字符 */ public static int getCheckCode(String code){ int checkCode = -1; if(code == null || "".equals(code)){ return -2; }else if(!Pattern.compile("^[0-9]*$").matcher(code).matches()){ checkCode = -1; }else{ try{ int evensum = 0; //偶数位的和 int oddsum = 0; //奇数位的和 evensum += Integer.parseInt(code.substring(11,12)); evensum += Integer.parseInt(code.substring(9,10)); evensum += Integer.parseInt(code.substring(7,8)); evensum += Integer.parseInt(code.substring(5,6)); evensum += Integer.parseInt(code.substring(3,4)); evensum += Integer.parseInt(code.substring(1,2)); evensum *= 3; odds