Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This program gives the ISBN-10 checksum
- //Prepared by Ethan Glover
- import java.util.Scanner;
- public class Prog13 {
- public static void main(String[] args) {
- //Ask for variables
- System.out.println("Enter the first 9 digits of an ISBN as integer: ");
- Scanner input = new Scanner (System.in);
- int isbn = input.nextInt();
- //Get integers
- int d1 = isbn / 100000000;
- int d2 = isbn / 10000000;
- int temp1 = isbn / 1000000;
- int d3 = temp1 % 10;
- int temp2 = isbn / 100000;
- int d4 = temp2 % 10;
- int temp3 = isbn / 10000;
- int d5 = temp3 % 10;
- int temp4 = isbn / 1000;
- int d6 = temp4 % 10;
- int temp5 = isbn / 100;
- int d7 = temp5 % 10;
- int temp6 = isbn / 10;
- int d8 = temp6 % 10;
- int d9 = isbn % 10;
- //Calculate 10 digit
- int d10 = ((d1 * 1 + d2 * 2 + d3 * 3 + d4 * 4 + d5 * 5 +
- d6 * 6 + d7 * 7 + d8 * 8 + d9 * 9) % 11);
- //If else
- //Examples 013601267 013031997:1 X
- if (d10 == 10)
- System.out.println("The ISBN-10 number is " + d1 + d2 + d3 + d4 + d5 + d6 + d7
- + d8 + d9 + "X");
- else
- System.out.println("The ISBN-10 number is " + d1 + d2 + d3 + d4 + d5 + d6 + d7
- + d8 + d9 + "" + d10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement