**3.9(Business: check ISBN-10) An ISBN-10 (International Standard Book Number)
consists of 10 digits: d1d2d3d4d5d6d7d8d9d10. The last digit, d10, is a checksum,
which is calculated from the other nine digits using the following formula:
(d1 * 1 + d2 * 2 + d3 * 3 + d4 * 4 + d5 * 5 +d6 * 6 + d7 * 7 + d8 * 8 + d9 * 9) % 11
If the checksum is 10, the last digit is denoted as X according to the ISBN-10
convention. Write a program that prompts the user to enter the first 9 digits and
displays the 10-digit ISBN (including leading zeros). Your program should read
the input as an integer. Here are sample runs:
VideoNote
Enter the first 9 digits of an ISBN as integer: 013601267
The ISBN-10 number is 0136012671
Enter the first 9 digits of an ISBN as integer: 013031997
The ISBN-10 number is 013031997X
**3.9(商业:检验ISBN-10)ISBN-10国际书写号由10位数字组成 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10,最后一位d10是校验和,它是使用下面的公式用另外9个数计算出来的
(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(包括前面起始位置的0)。程序应该读取一个整数输入。
以下是一个运行示例:
Enter the first 9 digits of an ISBN as integer: 013601267
The ISBN-10 number is 0136012671
Enter the first 9 digits of an ISBN as integer: 013031997
The ISBN-10 number is 013031997X
代码如下:
import java.util.Scanner;
public class Unite3Test9
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
System.out.println("请输入前九位数字");
int d1 = scan.nextInt();
int d2 = scan.nextInt();
int d3 = scan.nextInt();
int d4 = scan.nextInt();
int d5 = scan.nextInt();
int d6 = scan.nextInt();
int d7 = scan.nextInt();
int d8 = scan.nextInt();
int d9 = scan.nextInt();
int d10 = ((d1*1)+(d2*2)+(d3*3)+(d4*4)+(d5*5)+(d6*6)+(d7*7)+(d8*8)+(d9*9))%11;
if(d10==10)
{
System.out.print("The ISBN-10 number is "+d1);
System.out.print(d2);
System.out.print(d3);
System.out.print(d4);
System.out.print(d5);
System.out.print(d6);
System.out.print(d7);
System.out.print(d8);
System.out.print(d9);
System.out.print("x");
}else
{
System.out.print("The ISBN-10 number is "+d10);
System.out.print(d2);
System.out.print(d3);
System.out.print(d4);
System.out.print(d5);
System.out.print(d6);
System.out.print(d7);
System.out.print(d8);
System.out.print(d9);
System.out.print(d10);
}
}
}
结果如下: