ISBN

in ita •  4 months ago 

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;
}
}

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
image.png
please click it!
image.png
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)

The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.