Saturday, February 14, 2015

ISBN.java in a pgm



ISBN.java

public class ISBN
{
              public static void main(String[] args)
{

        int N = Integer.parseInt(args[0]);

            int sum = 0;
      for (int i = 2; i <= 10; i++)
     {
         int digit = N % 10;               
         sum = sum + i * digit;
         N = N / 10;
      }
    
      System.out.print("The full ISBN number is " + args[0]);
      if      (sum % 11 == 1) System.out.println("X");
      else if (sum % 11 == 0) System.out.println("0");
      else                   
      System.out.println(11 - (sum % 11));
   }
}

No comments:

Post a Comment