programmingex4 19 java

Solutions on MaxInterview for programmingex4 19 java by the best coders in the world

showing results for - "programmingex4 19 java"
Nabil
17 Sep 2016
1import java.util.Scanner;
2 
3public class ProgrammingEx4_19 {
4 
5 public static void main(String[] args) {
6  Scanner input = new Scanner(System.in);
7 
8  System.out.print("Enter the first 9 digits of an ISBN as integer:");
9  String isbn = input.next();
10  //Ascii code for 0-9 is 48-57
11  int d1 = (int)(isbn.charAt(0))-48;
12  int d2 = (int)(isbn.charAt(1))-48;
13  int d3 = (int)(isbn.charAt(2))-48;
14  int d4 = (int)(isbn.charAt(3))-48;
15  int d5 = (int)(isbn.charAt(4))-48;
16  int d6 = (int)(isbn.charAt(5))-48;
17  int d7 = (int)(isbn.charAt(6))-48;
18  int d8 = (int)(isbn.charAt(7))-48;
19  int d9 = (int)(isbn.charAt(8))-48;
20 
21  int d10 = (d1 * 1 + d2 * 2 + d3 * 3 + d4 * 4 + d5 * 5 + d6 * 6 + d7 * 7
22    + d8 * 8 + d9 * 9) % 11;
23 
24  System.out.print("The ISBN-10 number is " + d1 + d2 + d3 + d4 + d5 + d6
25    + d7 + d8 + d9);
26 
27  if (d10 == 10) {
28   System.out.print('X');
29  } else {
30   System.out.print(d10);
31  }
32 
33 }
34 
35}
36
similar questions
queries leading to this page
programmingex4 19 java