Guest User

Untitled

a guest
Dec 9th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. public boolean isValidISBN(String isbn)
  2. {
  3. if(isbn.length() == 10)
  4. {
  5. int sum = 0;
  6. int checkDigit = 0;
  7.  
  8. if (isbn.charAt(9) == 'X')
  9. {
  10. checkDigit = 10;
  11. Character.digit(isbn.charAt(9), 10);
  12. }
  13. for(int d = 10; d > 1; d--)
  14. {
  15. sum += d * Character.digit(isbn.charAt(d - 10), 10);
  16. }
  17. if((sum + checkDigit) % 11 == 0)
  18. {
  19. return true;
  20. }
  21. else
  22. {
  23. return false;
  24. }
  25. }
  26. else
  27. {
  28. return false;
  29. }
  30. }
Add Comment
Please, Sign In to add comment