Pearson com courses58 d73f 1512b55 AC9247cb334fe8310bAfc1b A
Solution
// Below is the working solution:
import java.util.Scanner;
public class Exercise03_09{
public static void main(String []args){
 Scanner scanner = new Scanner(System.in);
   
 System.out.print(\"Enter the first 9 digits of an ISBN as Integer: \");
 int isbn = scanner.nextInt();
   
 String temp = Integer.toString(isbn);
 int[] newInt = new int[9];
   
 int initValue = 9 - temp.length();
 String finalISBN = \"\";
   
 for(int i = 0; i < 9; i++) {
 //Append 0 if the bit is empty
 if(i < initValue) {
 newInt[i] = 0;
 finalISBN += \"0\";
 }
 //Else append the digit present at i-initValue position
 else {
 newInt[i] = temp.charAt(i - initValue) - \'0\';
 finalISBN += Integer.toString(newInt[i]);
 }
 }
   
 int checksum = 0;
 //Calculate the checksum according to the formula
 for(int i=0; i<9;i++) {
 checksum += newInt[i]*(i+1);
 }
   
 //Append the final 10th digit based on the mod(checksum,11) value.
 //If mod value is 10 then append x otherwise the digit.
 finalISBN += checksum%11 == 10? \'x\': Integer.toString(checksum%11);
   
 System.out.println(\"The ISBN-10 number is \" + finalISBN);
 }
 }

