xxxxxxxxxx
// To generate bank card checksum that satisfies Luhn algoritm specificaiton:
private int generateChecksum(String num) {
char[] binAccId = num.toCharArray();
int sum = 0;
for (int i = 0; i < binAccId.length; i++) {
int no = Character.getNumericValue(binAccId[i]);
if (i % 2 == 0) {
binAccId[i] = Character.forDigit(no * 2 > 9 ? no * 2 - 9 : no * 2, RADIX);
sum += Character.getNumericValue(binAccId[i]);
continue;
}
sum += no;
}
return 10 - (sum % 10) == 10 ? 0 : 10 - (sum % 10);
}