**5.36(商业应用:检测ISBN)使用循环简化编程练习题3.9。 **5.36(Business application: checking ISBN) Use loops to simplify Programming Exercise 3.9.
参考代码:
package chapter05;import java.util.Scanner;publicclassCode_26{publicstaticvoidmain(String[] args){int isbn,checkSum =0,divisor =100000000;
System.out.print("Enter the first 9 digits of an ISBN as integer: ");
Scanner input =newScanner(System.in);
isbn = input.nextInt();for(int i =0;i <9;i++){int dI = isbn / divisor %10;
checkSum += dI *(i+1);
divisor /=10;}
checkSum %=11;if(checkSum ==10)
System.out.printf("The ISBN-10 number is %d%dX", isbn /100000000, isbn %100000000);else
System.out.printf("The ISBN-10 number is %d%d%d", isbn /100000000, isbn %100000000, checkSum);}}
结果显示:
Enter the first 9 digits of an ISBN as integer:456287241
The ISBN-10 number is 4562872411
Process finished with exit code 0
第五章第三十六题(商业应用:检测ISBN)(Business application: checking ISBN)**5.36(商业应用:检测ISBN)使用循环简化编程练习题3.9。**5.36(Business application: checking ISBN) Use loops to simplify Programming Exercise 3.9.参考代码:package chapter05;import java.util.Scanner;public class Co