What you have here is proof that not everyone is going to play nice with "standards". Apparently Prentice Hall either miscalculated the ISBN for the book or simply don't care.
btw, your code is unnecessarilly long and convoluted.
The entire calculation can be handled in just a few lines of code (for ISBN10, similar code can be created for ISBN13):
public class Eleven {
private static boolean elevenProof(String number) {
if (number.length() != 10) {
return false;
}
int total = 0;
for (int i = 0; i < 9; i++) {
char c = number.charAt(i);
int digit = Character.digit(c, 10);
total += (10 - i) * digit;
}
int checksum = Character.digit(number.charAt(9), 10);
int modulo = total % 11;
return modulo == 11 - checksum;
}
public static void main(String[] args) {
String isbn = args[0];
System.out.println(isbn + " is " + (elevenProof(isbn) ? "valid" : "invalid"));
}
}
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.