HW4.36

 

 1 import java.util.Scanner;
 2 
 3 public class Solution
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner input = new Scanner(System.in);
 8 
 9         System.out.print("Enter the ISBN: ");
10         String isbn = input.nextLine();
11 
12         input.close();
13 
14         int numberOfISDN = Integer.parseInt(isbn.substring(0, 9));
15         int sum = 0;
16 
17         for(int i = 9; i > 0; i--)
18         {
19             sum += (numberOfISDN % 10) * i;
20             numberOfISDN /= 10; 
21         }
22 
23         if(sum % 11 == isbn.charAt(9))
24             System.out.println("Valid ISBN");
25         else if(sum % 11 == 10 && isbn.charAt(9) == 'X')
26             System.out.println("Valid ISBN");
27         else
28             System.out.println("Invalid ISBN");
29     }
30 }

 

posted @ 2016-08-19 11:54 WooDumpling 阅读(...) 评论(...) 编辑 收藏