ISBN Number in JAVA for ICSE/ISC

ICSE/ISC Program to Check ISBN Number

ISBN Number: ISBN stands for International Standard Book Number.

It is a unique numeric book identifier which is printed on every book.

The ISBN is based upon 10 Digit Code.

The ISBN Number is valid if :-

(1 X Digit 1 + 2 X Digit 2 + 3 X Digit 3 + 4 X Digit 4 + 5 X Digit 5 + 6 X Digit 6 + 7 X Digit 7 + 8 X Digit 8 + 9 X Digit 9 + 10 X Digit 10)
is Divisible by 11.


Example:

ISBN : 1401601499
Sum : 1*1 + 2*4 + 3*0 + 4*1 + 5*6 + 6*0 + 7*1 + 8*4 + 9*9 + 10*9 = 253
253 is divisible by 11

Output : Correct ISBN number.

Algorithm and Program given below :-

Algorithm :-

  • Input ISBN number
  • Store the ISBN number in two more variables
  • First check if the number is 10 digit number or not
  • If it is not a 10 digit number. Display “Illegal ISBN Number”
  • Otherwise calculate the sum of the digits by multiplying each digit with its respective position number.
  • Now check if the Sum is divisible by 11 or not.
  • If it is divisible, Display “Correct ISBN Number”
  • Otherwise, Display “Incorrect ISBN Number”
  • Compile and run the program
  
Program :-

import java.io.*;
import java.util.*;
class ISBN
{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
        long n,p,x,c=0,i,rev,sum=0;
        System.out.println("Enter ISBN Number");
        n= in.nextLong();
        p=n;
        x=n;
        while(p>0)
        {
            p=p/10;
            c++;
        }
        if(c!=10)
        {
            System.out.println("Illegal ISBN Number : "+n);
        }
        else
        {
            while(x>0)
            {
                rev=x%10;
                sum=sum+(rev*c);
                x=x/10;
                c--;
            }
            /*for(i=10;i>=1;i--)
            {
                rev=x%10;
                sum=sum+(rev*i);
                x=x/10;
            }*/
            if(sum%11==0)
            {
                System.out.println("It is a Valid ISBN Number : "+n);
            }
            else
            {
                System.out.println("It is not a Valid ISBN Number : "+n);
            }
        }
    }//end of main
}//end of class



Video Link of this program : https://youtu.be/DogI272ObWs

 

Follow me on Instagram


All the Best :)

Keep Learning :)

 


Comments

  1. What if the rest is 10, then is
    Check digit an "X". Can you help me...

    ReplyDelete

Post a Comment

Popular posts from this blog

Frequency of each digit of a number in Java

Trimorphic Number in JAVA

Tri-Automorphic Number in JAVA