Skip to content

Instantly share code, notes, and snippets.

Created December 24, 2014 13:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/0ed951c9abeb51b4b9d5 to your computer and use it in GitHub Desktop.
Save anonymous/0ed951c9abeb51b4b9d5 to your computer and use it in GitHub Desktop.
程序实例
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