有一个JAVA小程序,要求是。给你ISBN10的前9位,算出最后一位,然后输出新的isbn号码。计算第十位的方法是这样。校验码的计算方法10位1.假设某国际标准书号号码前9位是:7-309-04547;...
有一个JAVA小程序,要求是。给你ISBN10的前9位,算出最后一位,然后输出新的isbn号码。计算第十位的方法是这样。校验码的计算方法
10位
1.假设某国际标准书号号码前9位是:7-309-04547;
2.计算加权和S:S = 7×10+3×9+0×8+9×7+0×6+4×5+5×4+4×3+7×2 = 226;
3.计算S÷11的余数M:M = 226 mod 11 = 6;
4.计算11 - M 的差N:N = 11 − 6 = 5
如果N = 10,校验码是字母“X”;
如果N = 11,校验码是数字“0”;
如果N为其他数字,校验码是数字N。
所以,本书的校验码是5,故该国际标准书号为 ISBN 7-309-04547-5。
我写了这样的程序
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
/**
*
* @author Jinchuan
*/
import java.util.Scanner;
public class Exercise03_09 {
public static void main(String[] args) {
System.out.print("Enter the first 9-digit of an ISBN number as integer: ");
Scanner input = new Scanner(System.in);
int i = input.nextInt();
int a = (i / 100000000) * 10;
int b = ((i / 10000000)/10) * 9;
int c = ((i / 1000000)/100) * 8;
int d = ((i / 100000)/1000) * 7;
int e = ((i / 10000)/10000) * 6;
int f = ((i / 1000)/100000) * 5;
int g = ((i / 100)/1000000) * 4;
int h = ((i / 10)/10000000) * 3;
int j = ((i / 1)/100000000) * 2;
int r = (a + b + c + d + e + f + g + h + j) % 11 ;
if (r == 10)
System.out.print("The ISBN number is " + a + b + c + d + e + f + g + h + j + "X");
else
if (r == 11)
System.out.print("The ISBN number is " + a + b + c + d + e + f + g + h + j + "0");
else
System.out.print("The ISBN number is " + a + b + c + d + e + f + g + h + j + r);
}
}
但是,结果总是不对,。我做了下Debug。发现如果在第一步带入int值为013601267,在debug中。只会背带入为3080887. 我实在没头绪为什么会变成这样啊?
展开