Question

# To verify an ISBN, calculate 10 times the first digit, plus 9 times the second digit, plus 8 times the third and so on until we add 1 time the last digit. If the final number leaves no remainder when divided by 11, the code is a valid ISBN.

```				```
For example:
1. 0201103311:
10 * 0 + 9 * 2 + 8 * 0 + 7 * 1 + 6 * 1 + 5 * 0 + 4 * 3 + 3 * 3 + 2 * 1 + 1 * 1 = 55.
Since 55 leaves no remainder when divided by 11, hence it is a valid ISBN.
2. 007462542X:
10 * 0 + 9 * 0 + 8 * 7 + 7 * 4 + 6 * 6 + 5 * 2 + 4 * 5 + 3 * 4 + 2 * 2 + 1 * 10 = 176.
Since 176 leaves no remainder when divided by 11, hence it is a valid ISBN.
3. 0112112425:
10 * 0 + 9 * 1 + 8 * 1 + 7 * 2 + 6 * 1 + 5 * 1 + 4 * 2 + 3 * 4 + 2 * 2 + 1 * 5 = 71.
Since 71 leaves a remainder when divided by 11, hence it is not a valid ISBN.
```
```

# Design a program to accept a ten digit code from the user. For an invalid input, display an appropriate message. Verify the code for its validity in the format specified below:

```				```
Test your program with sample data and some random data.
Example 1:
INPUT CODE: 0201530821
OUTPUT:
SUM = 99
LEAVES NO REMAINDER â€“ VALID ISBN CODE
Example 2:
INPUT CODE: 035680324
OUTPUT: INVALID INPUT
Example 3:
INPUT CODE: 0231428031
OUTPUT:
SUM = 122
LEAVES REMAINDER â€“ INVALID ISBN CODE
```
```

# Share code with your friends

Code

```				```
import java.util.Scanner;
public class ISBN
{
public static void main(String args[])
{
int i=0,len=0,sum=0,n=0,digit=0;
char ch=' ';
String isbn="";
boolean invalidISBN=false;
Scanner sc=new Scanner(System.in);
System.out.print("ISBN Code: ");
isbn = sc.next();
isbn = isbn.trim().toUpperCase();
len = isbn.length();
n = 10;
if(len != n)
{
System.out.println("INVALID INPUT");
return;
}

for(i = 0; i < len; i++)
{
ch = isbn.charAt(i);

if((ch >= '0' && ch <= '9')||(ch=='X'&& i==(len-1)))
{
if(ch=='X')
{
sum=sum+10;
}
else
{
digit= Integer.parseInt(Character.toString(ch));
sum=sum+digit*n;
}
n--;
}
else
{
invalidISBN=true;

break;
}
}

if(invalidISBN==true)
{
System.out.println("INVALID INPUT");
}
else
{
if(sum % 11 == 0)
{
System.out.println("LEAVES NO REMAINDER - VALID ISBN CODE");
}
else
{
System.out.println("LEAVES REMAINDER - INVALID ISBN CODE");
}
}
}
}

```
```

Sale

50
Sale

150
Sale

200
Sale

50
Sale

50
Sale

50
Sale

50
Sale

50
Sale

50