欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JAVA 18位身份证号码校验码的算法

程序员文章站 2023-12-04 09:55:16
public static char doverify(string id) { char pszsrc[]=id.tochararray(); int is = 0; i...
public static char doverify(string id)
{
char pszsrc[]=id.tochararray();
int is = 0;
int iw[]={7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
char szvercode[] = new char[]{'1','0', 'x', '9', '8', '7', '6', '5', '4', '3', '2'};
int i;
for(i=0;i<17;i++)
{
is += (int)(pszsrc[i]-'0') * iw[i];
}
int iy = is%11;
return szvercode[iy];
}