I've started an Object Oriented Java Programming class but my code is still horribly lame.
I have to develop a program that runs in the console that asks for a 10 digit ISBN number and checks if its valid and corrects its last digit (the check digit) if its not valid, kinda like the applet in this page: http://www.cs.queens...t/isbncheck.htm
(the page is a reference site given by the teacher but it only gives me an idea of what the program has to display)
Anyway, i've managed to get a code that should take 9 digits and generate the check digit by computing the necessary calculations, here's the code:
public class ISBN
{
public static void main(String[] args)
{
int N = new Integer.parseInt(args[0]);
int sum = 0;
for (int i = 2; i <= 10; i++)
{
int digit = N % 10; // rightmost digit
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));
}
}
It compiles correctly but when i try to run it, it gives me this:
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at ISBN.main(ISBN.java:10) "
Any ideas about what's wrong?
Also i would like if someone could give me ideas on how to ask for a 10 digit ISBN and check if the check digit is correct,
THANK YOU SO MUCH FOR YOUR HELP

New Topic/Question
Reply




MultiQuote





|