AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.

# corejava-programming: WAP to check an ISBN Number

 An ISBN (International Standard Book Number) is a ten digit code which uniquely identifies a book. The first nine digits represent the Group, Publisher and Title of the book and the last digit is used to check whether ISBN is correct or not. Each of the first nine digits of the code can take a value between 0 and 9. Sometimes it is necessary to make the last digit equal to ten; this is done by writing the last digit of the code as X. 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*1 + 3*4 + 2*2 + 1*5 = 71 Since 71 leaves 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: Input Specifications. The first line contains - ISBN number Output Specification : Print ?N is a valid ISBN number? or ? N is not valid ISBN number? or ?N is an Invalid Input? Sample Input: 007462542X Sample output 007462542X is a valid ISBN number corejava x 352programming x 168 Posted On : 2016-11-28 14:42:23.0 Akash Prasad 2550 4

## Answers

 import java.util.Scanner; public class ISBNNumber { public static void main(String[] args) { Scanner input=new Scanner(System.in); String ISBN=input.nextLine(); if(ISBN.length()==10){ int temp=0; for(int i=10;i>0;i--){ temp=temp+i*(ISBN.charAt(10-i)==´X´?10:Integer.parseInt(Character.toString(ISBN.charAt(10-i)))); } System.out.println(ISBN+" is"+(temp%11==0?"":" not")+" a valid ISBN Number."); }else{ System.out.println(ISBN+" is an Invalid Input"); } } } Posted On : 2016-11-30 11:23:11 Satisfied : 2 Yes  4 No Rishi Kumar 523188221600Reply This Thread 3
Comments
passed 2 cases out of 4
Akash Prasad
25  5  0
Posted On :2016-11-30 15:11:09.0
Leave a Comment
Give me the failed 2 test cases, I'll modify the code and revert you back ASAP.
Rishi Kumar
523  1882  21600
Posted On :2016-12-03 23:08:48.0
Leave a Comment

Post Answer
Please Login First to Post Answer: Login

 Answer: