JAVA 检测ISBN

JAVA 检测ISBN_第1张图片

import java.util.Scanner;
public class Check {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the first 9 digits of an ISBN as integer: ");
        String s = input.next();
        int d10 = ((s.charAt(0) - '0') + (s.charAt(1) - '0')*2 + (s.charAt(2) - '0')*3 + (s.charAt(3) - '0')*4
                + (s.charAt(4) - '0')*5 + (s.charAt(5) - '0')*6 + (s.charAt(6) - '0')*7 + (s.charAt(7) - '0')*8
                + (s.charAt(8) - '0')*9) % 11;
        if(d10 == 10)
            System.out.println("The ISBN number is " + s + "X");
        else
            System.out.println("The ISBN number is " + s + d10);
    }
}

 

你可能感兴趣的:(java,开发语言,算法)