[Solved] JAVA ISBN-10 Number: Find 10th digit [closed]


nextInt() consumes the entire token 013601267, not just a single digit, which was not your plan. A much easier approach could be to consume it as a single string and then iterate over the characters:

String num = s.next();
int sum = 0;
for (int i = 1; i <= num.length(); ++i) {
    sum += (i * num.charAt(i - 1) - '0');
}

int d10 = (sum % 11);
if (d10 == 10) {
    System.out.println("The ISBN-10 number is " + num + "X");
} else {
    System.out.println("The ISBN-10 number is " + num + d10);
}

solved JAVA ISBN-10 Number: Find 10th digit [closed]