//存储身份证前17位
int[] card = new int[17];
//存放对应系数
int[] data = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
char[] c = {'1','0','x','9','8','7','6','5','4','3','2'};
Scanner scanner=new Scanner(System.in);
//初始化
int sum = 0;
for (int i = 0; i < 17; i++) {
System.out.println("一次输入前17位");
card[i]=scanner.nextInt();
}
for (int i = 0; i < 17; i++) {
sum += card[i]*data[i];
}
//输出身份证最后一位
System.out.println(c[sum%11]);
scanner.close();
java--身份证号验证
最新推荐文章于 2024-03-12 13:23:59 发布