1public boolean isIdCard(String arrIdCard) {
2 int sigma = 0;
3 Integer[] a = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
4 String[] w = {"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"};
5 for (int i=0; i<17; i++) {
6 int ai = Integer.parseInt(arrIdCard.substring(i,i+1));
7 int wi = a[i];
8 sigma += ai * wi;
9 }
10 int number = sigma % 11;
11 String check_number = w[number];
12 //return check_number;
13 //System.out.println(check_number);
14 if (!arrIdCard.substring(17).equals(check_number)) {
15 return false;
16 } else {
17 return true;
18 }
19 }
回复 更多评论