Sha256: dd40c923b4d3775b49fc722fa948f38a15a5d9602c66683f49619f81d8dcd99e
Contents?: true
Size: 894 Bytes
Versions: 112
Compression:
Stored size: 894 Bytes
Contents
class IsbnVerifier { boolean isValid(String stringToVerify) { String isbn = stringToVerify.replace("-", ""); int total = 0; if (isbn.length() != 10) { return false; } for (int i = 0; i < isbn.length() - 1; i++) { char currentChar = isbn.charAt(i); if(Character.isDigit(currentChar)) { int currentCharVal = Character.getNumericValue(currentChar); total += currentCharVal * (10 - i); } else { return false; } } char finalChar = isbn.charAt(isbn.length() - 1); if (Character.isDigit(finalChar)) { total += Character.getNumericValue(finalChar); } else if (finalChar == 'X') { total += 10; } else { return false; } return total % 11 == 0; } }
Version data entries
112 entries across 112 versions & 1 rubygems