# Program does not work

• September 27th, 2013, 09:02 AM
cldance5678
Program does not work
Hi, newbie to the forum
I am a beginner in java eclipse and having a problem with the program i had to write. The program ask the user to enter 9 digit then it is to produce the 9 numbers plus the 10th number. That does not happen. Any help would be appreciated thanks.

John
P/S please let me know if i posted correctly.

[highlight = java]

import java.util.Scanner;
public class Exercise3_9 {

public static void main(String[] args) {
Scanner input = new Scanner (System.in);

while (true) {
//Prompt the user to enter first 9 ISBN digits
System.out.print("Enter the first 9 digits of the ISBN: ");
int d1 = input.nextInt();
int d2 = input.nextInt();
int d3 = input.nextInt();
int d4 = input.nextInt();
int d5 = input.nextInt();
int d6 = input.nextInt();
int d7 = input.nextInt();
int d8 = input.nextInt();
int d9 = input.nextInt();

// Calculate
int d10 = ((d1 * 1) + (d2 * 2) + (d3 * 3) + (d4 * 4) + (d5 * 5) + (d6
* 6) + (d7 * 7) + (d8 * 8) + (d9 * 9))% 11;

if (d10 ==10)
System.out.println("The ISBN-10 number is " + "x");
else
System.out.println("The ISBN-10 number is " + "");
System.out.println();
}
}
}

[/highlight]
• September 27th, 2013, 09:12 AM
KevinWorkman
Re: Program does not work
What happens instead? What did you find out when you stepped through this with a debugger, or at least added some print statements, to figure out when the program's execution differs from your expectation?
• September 27th, 2013, 03:55 PM
cldance5678
Re: Program does not work
Quote:

Originally Posted by KevinWorkman
What happens instead? What did you find out when you stepped through this with a debugger, or at least added some print statements, to figure out when the program's execution differs from your expectation?

Kevin,
This is what i get.

Enter the first 9 digits of the ISBN: 013601267

What needs to happen is this:
Enter the first nine digits of an ISBN as integer: 013601267
The ISBN-10 number is 0136012671

John
• September 27th, 2013, 04:18 PM
aussiemcgr
Re: Program does not work
Put a print statement after the first "input.nextInt();" and tell us when it gets executed. I suspect the nextInt() method doesn't trigger until an "end-case" for the input is reached. By that, I mean: how does the Scanner know your first integer is supposed to be "0" instead of "013601267"? If it is taking "013601267" as your first int (which I suspect it is), your program will hang on the second nextInt(), since it is waiting another int to be inputted.
• September 27th, 2013, 08:36 PM
cldance5678
Re: Program does not work
I am sorry but i am really new at this programming stuff, so i don't quite understand the print statement.
• September 27th, 2013, 10:28 PM
GregBrannon
Re: Program does not work
KW's point is that you have 9 calls to input.nextInt(), and the first call is taking the entire user input of "013601267", and is waiting for the user to input a second digit, because that's how the nextInt() method works. Try giving the input statements one character (or digit) at a time separated by white space, as in: 0<space>1<space>3<space>6, etc. . .