Published: 14 May 2024 › Updated: 14 May 2024

ISBN
class IsbnVerifier {
boolean isValid(String stringToVerify) {
int sum =0;
stringToVerify = stringToVerify.replaceAll("-", "");
if (stringToVerify.length() != 10) return false;
for(int i=0; i<stringToVerify.length(); i++){
if (Character.isLetter(stringToVerify.charAt(i))){
if (i == stringToVerify.length()-1 && stringToVerify.charAt(i) =='X'){
sum += 10;
break;
}
else return false;
}
char numberToBe = stringToVerify.charAt(i);
int num = numberToBe - '0';
sum += num \* (10-i);
}
return sum % 11 == 0;
}
}
Leave ISBN to:
Read more #ita posts
Best Posts From Alessandra
We have not curated any of drago18121996's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.