Old 06-24-2014, 10:06 PM   #1 (permalink)
Status: Senior Member
Posts: 1,518

Default help me fix my java codeim suppose to check isbn 13 with my code.

code is basically I enter the first 12 digits of an ISBN-13 as a string, then it;s going to give me the isbn 13 code? something wrong with my code? please help

public class isbnchecker {
public static void main(String[] args) {
Scanner scan= new Scanner(;
System.out.println("input an isbn");
String isbn = scan.nextLine();
isbnchecker main = new isbnchecker();
System.out.println(isbn + main.checkISBN(isbn));

private boolean checkISBN (String isbn){
char[] isbnChar = isbn.toCharArray();
//check if the length is 13
if (isbnChar.length != 13)
return false;
//check if only digits

for(int i=0;i<isbnChar.length;i++){
if (!Character.isDigit(isbnChar[i]))
return false;
//check if the checknumber is correct
int sum = 0;

for(int i=0;i<(isbnChar.length-1);i=i+2){
sum = sum + Character.getNumericValue(isbnChar[i]);
for (int i=1;i<isbnChar.length;i=i+2){
sum = sum + (Character.getNumericValue(isbnChar[i])*3);
int CheckDigit = 10-sum%10;
int LastDigit = Character.getNumericValue(isbnChar[isbnChar.length]);
if (CheckDigit != LastDigit)
return false;
return true;}}
Jack is offline   Reply With Quote



Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
java code help? I can't seem to get this ISBN 13 right, 10-(d1 +3d2 +d3 +3d4 +d5 +3d6 +d7 +3d8 +d9 +3d10 +d11 +3d12) % 10, the formula? Tyrone Coding 2 06-25-2014 06:06 AM
can someone fix my java code? it's about ISBN 13 code change, I keep getting error messages? Tyrone Coding 1 06-25-2014 02:06 AM
can someone help me with this java code? I'm suppose to translate letters to phone numbers? Ron Coding 2 03-14-2014 07:06 PM
GCSE Computing ISBN Check Digit? franXx JavaScript 0 04-29-2012 06:07 PM
JAVA Code Help: ISBN Checker Shirapsynge Coding 0 09-15-2011 10:06 PM