Import for the required classes to work E import java util. Scanner: class that
ID: 3795605 • Letter: I
Question
Import for the required classes to work E import java util. Scanner: class that encapsulates the code public class Exerciseo3 o9 Driver method public static void main (Stringt ara) I/Scanne claas objects scanner input new scanner (syatem.in) //Promt system out. print Enter the first 9 digita of an ISBN as Integer: //Read the data aa integer int isbn input nextInt //convert the data to integer array for the checksum calealation String temp Integer tostring iabn) int [1 newInt new int [temp length 01: for (int 1 0: i temp length it newIntli] temp .charAt (i) //calculate the check aum int checksum newInt to 1.1) MInt (11.2) neteint 121.3) new Int 131.4 (nevrint 171 B) newInt (81.9) Prcat result system. out printin ("The Is io umber (Integer toString (iabn)) Integer. tostring checksum)))Explanation / Answer
import java.util.Scanner;
public class Exercise03_09 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Enter the first 9 digits of an ISBN as Integer: ");
int isbn = input.nextInt();
String temp = Integer.toString(isbn);
int[] newInt = new int[9];
int initVal = 9 - temp.length();
String appendVal = "";
for(int i=0;i<9;i++){
if(initVal > 0 && i<initVal){
newInt[i] = 0;
appendVal = appendVal + "0";
continue;
}
if(initVal > 0)
newInt[i] = temp.charAt(i-initVal) - '0';
else
newInt[i] = temp.charAt(i) - '0';
}
int checkSum = ((newInt[0]*1) + (newInt[1]*2) + (newInt[2]*3) + (newInt[3]*4) + (newInt[4]*5) + (newInt[5]*6) + (newInt[6]*7) + (newInt[7]*8) + (newInt[8]*9)) % 11;
System.out.println("The ISBN-10 Number is " + appendVal +
(Integer.toString(isbn)) + (Integer.toString(checkSum)));
}
}