Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
程序实例
publicclassId18 {
int[] weight={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; //十七位数字本体码权重
char[] validate={ '1','0','X','9','8','7','6','5','4','3','2'}; //mod11,对应校验码字符值
publicchargetValidateCode(String id17){
intsum=0;
intmode=0;
for(inti=0;i<id17.length();i++){
sum=sum+Integer.parseInt(String.valueOf(id17.charAt(i)))*weight[i];
}
mode=sum%11;
returnvalidate[mode];
}
publicstaticvoidmain(String[] args){
16Id18 test=newId18();
System.out.println("该身份证验证码:"+test.getValidateCode("14230219700101101")); //该身份证校验码:3
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment