Advertisement
mrScarlett

isbn java

Jan 24th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. * @author (your name)
  2. * @version (a version number or a date)
  3. */
  4. import java.util.*;
  5. public class checkDigit
  6. {
  7. public static void main(String[] args) {
  8. Scanner input = new Scanner(System.in);
  9. int value=0;
  10. int odd=0;
  11. int even=0;
  12. int checkDigit=0;
  13. System.out.println("Enter ISBN");
  14. String isbn=input.next();
  15. for (int x=0;(x<isbn.length()-1);x++){
  16. System.out.println(isbn.charAt(x));
  17. value=Character.getNumericValue(isbn.charAt(x));
  18. if (x%2==0){
  19. odd+=value;
  20. }
  21. else{
  22. even+=value;
  23. }
  24. }
  25.  
  26. even=even*3;
  27. value=(odd+even)%10;
  28. if (value==0){
  29. checkDigit=value;
  30. }else{
  31. checkDigit=10-value;
  32. }
  33. System.out.println("ISBN check digit is..."+checkDigit);
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement