Problem Statement
The last digit is calculated in such a way that the last digit plus 2 times the ninth digit, plus 3 times the eighth digit, plus 4 times the seventh digit and so on, ..., plus 9 times the second digit, plus 10 times the first digit is evenly divisible by 11. Sometimes, the formula gives 10 for the check digit. In this case, publishers use the character 'X' to represent the check digit 10.
Your task is, given the first 9 digits of ISBN, return the check digit.
Definition
- Class:
- ISBNumber
- Method:
- checkDigit
- Parameters:
- String
- Returns:
- char
- Method signature:
- char checkDigit(String num)
- (be sure your method is public)
Constraints
- num contains exactly 11 characters, 9 of them are digits [0-9] and the other two are dashes '-'
- second character of num is a dash, another dash will occupy a place in num between the 4th and the 9th character inclusive
Examples
"1-861000-27"
Returns: '8'
8 + 2*7 + 3*2 + 4*0 + 5*0 + 6*0 + 7*1 + 8*6 + 9*8 + 10*1 = 165, is divisible by 11. (Ivor Horton. Beginning Java)."0-07-882149"
Returns: '5'
(Harley Hahn. The Unix Companion)."0-471-11709"
Returns: '9'
(Bruce Schneier. Applied Cryptography)."0-425-09961"
Returns: 'X'
10 + 2*1 + 3*6 + 4*9 + 5*9 + 6*0 + 7*5 + 8*2 + 9*4 + 10*0 = 132, is divisible by 11. (Agatha Christie. Thirteen at Dinner).