的ISBN-10由10位數字:D1,D2,D3,D4,D5,D6,D7,D8,D9,D10。最後的數字,D10,是校驗,它是從使用 其它九個數字計算公式如下:
(D1 * 1 + D2×2 + D3×3 + D4×4 + D5 * 5 + d6 * 6 + d7 * 7 + d8 * 8 + d9 * 9)%11
如果校驗和爲10,則根據ISBN-10 慣例將最後一位數字表示爲X.
編寫一個程序,提示用戶輸入前9位數字並顯示10位ISBN(包括前導零)。您的程序應該將輸入讀取爲整數。
下面是樣品運行:
輸入第9個的ISBN位數爲整數:013601267
的ISBN-10號是0136012671
我的代碼:
import java.util.Scanner;
public class ISBN_Number {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int[] num = new int[9];
System.out.println("Enter the first 9 digits of the an ISBN as integer: ");
for (int i = 0; i < num.length; i++) {
for (int j = 1; j < 10; j++) {
num[i] = s.nextInt() * j;
}
}
int sum = 0;
for (int a = 0; a < 10; a++) {
sum += num[a];
}
int d10 = (sum % 11);
System.out.println(d10);
if (d10 == 10) {
System.out.println("The ISBN-10 number is " + num + "X");
} else {
System.out.println("The ISBN-10 number is" + num);
}
}
}
ISSUE: 我是學習java的新手,因此我無法解決這個問題。有人可以告訴我我錯在哪裏,因爲我沒有得到預期的結果。謝謝。
你正在閱讀「掃描儀」中的81個整數...... –
你介意我是怎麼做的。我對我如何閱讀81個整數感到困惑。 –