# elementary but urgent problem

3 replies [Last post]
bnuessler
Offline
Joined: 2007-10-14

I would like to take a 10-digit input, which is in a string called input, and take out the first 9 digits and put them into an int called isbn. Then, take out the last digit and put it into an int called vCheck. Now, this is an ISBN problem, so I also need something that checks if vCheck is an X. If vCheck is an X, then it has to be switched to 10, else 'not sure what to put here'.
Then, later on using the first 9 digits a calculation will take place. Out of this calculation the program will get a 10th digit and I want the program to check if this new digit (checkdigit) equals the initial 10th digit from before (vCheck). If they are equal then the program will output ("correct"), else it will output ("a correct ISBN would be: " + isbn + checkdigit).
I hope I'm not being confusing here, can anyone help me?

## Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dnbphysicist
Offline
Joined: 2007-10-14

First you can take the string of all ten characters and then use the substring method from the string class to break it up into two smaller strings. Then call int isbn = Integer.parseint(string a) and vCheck = Integer.parseInt(string b) to convert each string to two seperate ints. To see if vCheck is equal to X use if (vCheck==X) { statements } The rest should be self explanatory.

This page is very useful btw: http://java.sun.com/j2se/1.4.2/docs/api/

Message was edited by: dnbphysicist

bnuessler
Offline
Joined: 2007-10-14

I couldnt really find anything for that link.. but.. if i have a String x, and an int checkdigit, where checkdigit has a value... how do i do this --> x = checkdigit; ?

dnbphysicist
Offline
Joined: 2007-10-14

So you want to convert an int to a String?

String x = "" + checkdigit;