Java Program for ISBN Number2 min read

In this tutorial, we will learn about the ISBN (International Standard Book Number) and write a program to check for the ISBN Number in Java

ISBN number program in java.

ISBN is a 10-digit unique number that is is carried by almost each and every book. It is used to identify the book uniquely. With the help of ISBN, we can easily find a book. The ISBN is legal if 1*digit1 + 2*digit2 + 3*digit3 + 4*digit4 + 5*digit5 + 6*digit6 + 7*digit7 + 8*digit8 + 9*digit9 + 10*digit10 is divisible by 11.

The first nine digits of the ISBN number are used to represent the Title, Publisher, and Group of the book, and the last digit is used for checking whether ISBN is correct or not.

Example:

Let us consider a number: 1259060977
Check:
Sum = 1*10 + 2*9 + 5*8 + 9*7 + 0*6 + 6*5 + 0*4 + 9*3 + 7*2 + 7*1 = 209
Now divide the sum by 11 and see if the remainder obtained is zero or not.
rem = 209%11 = 0
Since, rem = 0, therefore 1259060977 is a legal ISBN number.


Steps to write Program for ISBN number Java

  • First, take a 10-digit number input from the user.
  • The second step is to check if the entered number is 10-digits or not because a number cannot be ISBN if it is not a 10-digit number. If it is not a 10-digit number then we will display an invalid message otherwise follow the steps below.
  • For the sum, we need to multiply each digit by 1 to 10 from left to right.
  • Lastly, divide the sum and check if the remainder is zero or not, if it is zero then the entered number is an ISBN number else it is not.

Now let us implement the above logic to check whether the number is an ISBN or not in java.


Java Program to check for ISBN Number

Output: After execution following result will be displayed.

You may create a separate user define function where you can pass the entered number and do the necessary calculation and at the end return the result to the main function. This is how you calculate the ISBN number java.


MORE

C++ Structures

In the C/C++ programming language, the structure is user-defined data types that allow us to store the combination of different data types together. All the …
Read More

C++ Static Keyword

Static s a keyword in C++ that is when used with different types gives different meanings. static keyword can be used with variables in a …
Read More

C++ Templates

Templates in C++ are the powerful feature that allows us to write generic programs (generic classes and generic functions). A single class or function is …
Read More

C++ Friend Function

There are private and protected members in a class that is inaccessible from outside of the class, constituting one of the concepts of object-oriented programming …
Read More

this Pointer in C++

In C++, this is a keyword that refers to the current instance of a class and this pointer holds the address or points to the …
Read More

Inheritance in C++

Inheritance is one of the most important concepts of object-oriented programming. In C++, inheritance is the process of deriving the properties and behaviors of one …
Read More