Program that prompts the user to enter the first 9 digits of an ISBN number and displays the 10-digit ISBN (including leading zeros).
Click here to see other solutions to Introduction to Java Programming.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> */<br /><br />import java.util.Scanner;<br /><br />public class Ex03_09 {<br /> public static void main(String[] args) {<br /> int isbnFirstNineDigits, d1, d2, d3, d4, d5, d6, d7, d8, d9, isbnLastDigit;<br /><br /> Scanner input = new Scanner(System.in);<br /><br /> System.out.print("Enter the first 9 digits of an ISBN as integer: ");<br /> isbnFirstNineDigits = input.nextInt();<br /><br /> d9 = isbnFirstNineDigits % 10;<br /> d8 = (isbnFirstNineDigits / 10) % 10;<br /> d7 = (isbnFirstNineDigits / 100) % 10;<br /> d6 = (isbnFirstNineDigits / 1000) % 10;<br /> d5 = (isbnFirstNineDigits / 10000) % 10;<br /> d4 = (isbnFirstNineDigits / 100000) % 10;<br /> d3 = (isbnFirstNineDigits / 1000000) % 10;<br /> d2 = (isbnFirstNineDigits / 10000000) % 10;<br /> d1 = (isbnFirstNineDigits / 100000000) % 10;<br /><br /> isbnLastDigit = (d1 * 1 + d2 * 2 + d3 * 3 + d4 * 4 + d5 * 5 + d6 * 6 <br /> + d7 * 7 + d8 * 8 + d9 * 9) % 11;<br /><br /> if (isbnLastDigit == 10) {<br /> System.out.println("The ISBN-10 number is " + d1 + d2 + d3 + d4 + d5<br /> + d6 + d7 + d8 + d9 + "X");<br /> } else<br /> System.out.println("nThe ISBN-10 number is " + d1 + d2 + d3 + d4 + d5<br /> + d6 + d7 + d8 + d9 + isbnLastDigit);<br /> }<br />}<br /> |
Program sample run |
1 2 |
<br /> |