I also have a query about ISBN. Some books have one ISBN, SOME have two. Is it appropriate to use ISBN AS a primary key for a book table ( as I have seen it in one book).
What is ISBN. What can be the appropriate primary key for book & other products like laptops.
Please post such questions as a new thread so the original question is not derailed.
Ezzaral
Posting Genius
15,985 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
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"));
}
}
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337