/*
Enter the ISBN numbers of the book: 013601267
0136012671
*/
import java.util.Scanner;
publicclass CheckISBN1 {
publicstaticvoidmain(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the ISBN numbers of the book: ");
String s = input.next();
for (int i = 0; i < s.length(); i++) {
if (!Character.isDigit(s.charAt(i)) || s.length() > 9) {
System.out.println("The string must be numbers.");
System.exit(0);
}
}
s = computeTenth(s);
System.out.println(s);
}
publicstatic String computeTenth(String s) {
StringBuilder stringBuilder = new StringBuilder(s);
int[] isbn = newint[9];
int Ten = 0;
for (int i = 0; i < s.length(); i++) {
isbn[i] = charToInt(s.charAt(i));
Ten += isbn[i] * (i + 1);
}
Ten %= 11;
if (Ten == 10)
stringBuilder.append('X');
else
stringBuilder.append(Ten);
return stringBuilder.toString();
}
publicstaticintcharToInt(char ch) {
return ch - 48;
}
}