public class BinaryTest
{
private static int[] weight = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
private static int[] check = { 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 };
public static void main(String[] args)
{
System.out.println(getVerifyCode("42108719881002761"));
}
public static String getVerifyCode(String idcard)
{
String result = null;
int sum = 0;
for (int i = 0; i < idcard.length(); i++)
{
sum += Integer.parseInt(idcard.substring(i, i + 1)) * weight[i];
}
result = (sum % 11) == 2 ? "X" : String.valueOf(check[sum % 11]);
return result;
}
}