java isbn_JAVA ISBN计算问题。。简单JAVA编程

有一个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. 我实在没头绪为什么会变成这样啊?

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值