package practice;
import java.util.Scanner;
public class Demo1 {
public static void main(String[] args) {
compare();//封装
}
public static void compare() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入您的身份证号码:");
String s = scanner.nextLine();//获取字符串
//System.out.println(s);
int n,sum = 0;
int[] ary = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
char[] ch={'1','0','x','9','8','7','6','5','4','3','2'};
for(int i=0; i<s.length()-1; i++){
sum += (s.charAt(i)-'0')*ary[i];
//System.out.println("sum单个="+(s.charAt(i)-'0')+",i是"+i+"sum="+sum);
}
//System.out.println(sum);
n = sum % 11;
//System.out.println("n="+n);
char l = ch[n];
//System.out.println(l);
if((l-'0') == (s.charAt(s.length()-1)-'0')){
System.out.println("身份证有效!");
}else{
System.out.println("身份证无效!");
}
}
}