int validate = 0; for (int i = 1; i <= number.length(); i++) { char x = getCharFromString(number, i - 1); int m = getIntFromChar(x); if (m != 0) { if (i < 9) { validate = validate + m * (i + 1); } else { validate = validate + m * (i - 8); } } } validate = validate % 11; if (validate == 10) { return"Y"; } else { returnString.valueOf(validate); } }
/** * 从字符串中获取指定位置的字符 * * @param number * 号 * @param position * 位置 * @return 字符 */ private static char getCharFromString(String number, int position) {