Programming Examples
Java program to check given ISBN is valid or not
The International Standard Book Number (ISBN) is a unique numeric book identifier which is printed on every book. The ISBN is based upon a 10-digit code. The ISBN is legal if:
1 x digit1 + 2 x digit2 + 3 x digit3 + 4 x digit4Â + 5 x digit5Â + 6 x digit6Â + 7 x digit7 + 8 x digit8Â + 9 x digit9 + 10 x digit10 is divisible by 11.
Example:Â
For an ISBN 1401601499
Sum=1 x 1 + 2 x 4 + 3 x 0 + 4 x 1 + 5 x 6 + 6 x 0 + 7 x 1 + 8 x 4 + 9 x 9 + 10 x 9 = 253 which is divisible by 11.
Write a program to:
(i) Input the ISBN code as a 10-digit integer.
(ii) If the ISBN is not a 10-digit integer, output the message, "Illegal ISBN" and terminate the program.
(iii) If the number is 10-digit, extract the digits of the number and compute the sum as explained above. If the sum is divisible by 11, output the message, "Legal ISBN". If the sum is not divisible by 11, output the message, "Illegal ISBN".
Output