.5.47 (Business: check ISBN-13) ISBN-13 is a new standard for identifying books.
ID: 3814105 • Letter: #
Question
.5.47 (Business: check ISBN-13) ISBN-13 is a new standard for identifying books. It uses 13 digits didzd dsded7dsdigd,od, 1d12d 3. The last digit d13 is a checksum, which is calculated from the other digits using the following formula: If the checksum is 10, replace it with e. Your program should read the input as a string. If the input is incorrect, display invalid input. Here is a sample run: Sample Run for Exercise05 47 Enter input data for the program (Sample data provided below You may modify it.) 978013213080 show the sample output Using the Preceeding Input Reset command java Exercise05 47 Enter the first 12-digit of an ISBN number as a string: 978013213080 The ISBN number isExplanation / Answer
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
String isbn=null;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first 12 digits of an ISBN as a string:");
isbn =sc.next();
if(isbn.isEmpty() || isbn==null || isbn.length()>12 || isbn.length()<12){
System.out.println("Invalid input");
}
else{
int chcksum,d1 = 0,d2 = 0,d3 = 0,d4 = 0,d5 = 0,d6 = 0,d7 = 0,d8 = 0,d9 = 0,d10 = 0,d11 = 0,d12=0;
d1=isbn.charAt(0);
d2=isbn.charAt(1);
d3=isbn.charAt(2);
d4=isbn.charAt(3);
d5=isbn.charAt(4);
d6=isbn.charAt(5);
d7=isbn.charAt(6);
d8=isbn.charAt(7);
d9=isbn.charAt(8);
d10=isbn.charAt(9);
d11=isbn.charAt(10);
d12=isbn.charAt(11);
chcksum =(10-(d1+(3*d2)+d3+(3*d4)+d5+(3*d6)+d7+(3*d8)+d9+(3*d10)+d11+(3*d12))%10);
if(chcksum==10){
chcksum=0;
}
isbn=isbn+chcksum;
System.out.println("The ISBN number is:"+isbn);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.