Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. // Prompt the user to enter the first 9 digits of a 10-digit ISBN
  2. System.out.print("Enter the first 9 digits of an ISBN as integer: ");
  3. int isbn = input.nextInt();
  4.  
  5. // Extract the digits of the ISBN
  6. int d1 = isbn / 100000000;
  7. int remainingDigits = isbn % 100000000;
  8. int d2 = remainingDigits / 10000000;
  9. remainingDigits %= 10000000;
  10. int d3 = remainingDigits / 1000000;
  11. remainingDigits %= 1000000;
  12. int d4 = remainingDigits / 100000;
  13. remainingDigits %= 100000;
  14. int d5 = remainingDigits / 10000;
  15. remainingDigits %= 10000;
  16. int d6 = remainingDigits / 1000;
  17. remainingDigits %= 1000;
  18. int d7 = remainingDigits / 100;
  19. remainingDigits %= 100;
  20. int d8 = remainingDigits / 10;
  21. remainingDigits %= 10;
  22. int d9 = remainingDigits;
  23.  
  24. // Compute d10
  25. int d10 = (d1 * 1 + d2 * 2 + d3 * 3 + d4 * 4 + d5 * 5
  26. + d6 * 6 + d7 * 7 + d8 * 8 + d9 * 9) % 11;
  27.  
  28. // Display the 10-digit ISBN
  29. System.out.println("The ISBN-10 number is " + d1 + d2 + d3 + d4 + d5
  30. + d6 + d7 + d8 + d9);
  31. if (d10 == 10)
  32. System.out.println("X");
  33. else
  34. System.out.println(d10);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement