import java.util.Scanner; public class HW1Demo { /** * report bugs to xusun09@gmail.com */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Please enter the first 9 digits of the ISBN number:"); Scanner keyboard = new Scanner (System.in); String number = keyboard.nextLine(); number = number.replaceAll("-",""); int first = Integer.parseInt(number.substring(0, 1)); int second = Integer.parseInt(number.substring(1, 2)); int third = Integer.parseInt(number.substring(2, 3)); int fourth = Integer.parseInt(number.substring(3, 4)); int fifth = Integer.parseInt(number.substring(4, 5)); int sixth = Integer.parseInt(number.substring(5, 6)); int seventh = Integer.parseInt(number.substring(6, 7)); int eighth = Integer.parseInt(number.substring(7, 8)); int ninth = Integer.parseInt(number.substring(8, 9)); int tenth = 11 - (10*first + 9*second + 8*third + 7*fourth + 6*fifth + 5*sixth + 4*seventh + 3*eighth + 2*ninth)%11; System.out.println("The last digit is: " + tenth); } }
Monday, September 14, 2009
HW1 example
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment