switch-if 给定9位数生成ISBN

 1 package com.java.test;
 2 
 3 import java.util.Scanner;
 4 
 5 public class practice3_09 {
 6 
 7     public static void main(String[] args) {
 8         Scanner sc = new Scanner(System.in);
 9         System.out.print("Enter the first 9 digits of an ISBN as integer:");
10         String s = sc.nextLine();
11         //char[] arr =s.toCharArray();
12         int[] num = new int[s.length()];
13         for (int i = 0; i < num.length; i++) {
14             num[i] = (int)s.charAt(i) - '0';
15         }
16         int sum = 0;
17         for (int i = 0; i < num.length; i++) {
18             sum += (i + 1)*num[i];
19         }
20         int d = sum % 11;
21         if(d == 10) {
22             System.out.println(s + "X");
23         } else {
24             System.out.println(s + d);
25         }
26     }
27 
28 }
原文地址:https://www.cnblogs.com/xiaoyingying/p/7516116.html