Q:

java program to calculate the ISBN 13 digits

0

ISBN-13 is a new standard for identifying books in a library. it uses 13 digits number where ISBN 13: d1d2d3d4d5d6d7d8d9d10d11d12d13

the last digit d13 is a checksum, which is calculated from other 12 digits using the following formula:

d13 = 10 - (d1+3d2+d3+3d4+d5+3d6+d7+3d8+d9+3d10+d11+3d12+d13)%10

if the checksum is 10, replace it with 0.

write a java program that calcualte the checksum by asking teh librarian to enter 12 digits of ISBN then print the result. (Hint: use only 1 identifier(variable) for reading numbers).

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
class Main{
public static void main(String[] args){
 Scanner input=new Scanner(System.in);
 System.out.println("ISBN13 Checksum Calclator");
 int d13,totalD=0;
 int i=1,d;
 while(i<=12)
 {
     System.out.print("Enter d"+i+": ");
     d=input.nextInt();
     if(i%2==0)
     totalD=totalD+3*d;
     else totalD=totalD+d;
     i++;
 }
 d13=10-totalD%10;
 if(d13==10)
 d13=0;
 
 System.out.println("The Checksum is "+d13);  
}}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now