Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Program does not work

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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]


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program does not work

    Quote Originally Posted by KevinWorkman View Post
    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

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default 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.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  5. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default 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. . .

Similar Threads

  1. HELP!! Cant get point program to work
    By Lashickk in forum What's Wrong With My Code?
    Replies: 10
    Last Post: July 30th, 2013, 01:26 AM
  2. Program doesn't work!
    By Mrcinica in forum What's Wrong With My Code?
    Replies: 15
    Last Post: May 16th, 2013, 10:23 AM
  3. No idea why this program doesn't work
    By Diesel298 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 7th, 2012, 01:01 PM
  4. [SOLVED] (Beginner) Program doesnt work
    By moneyman021 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: January 15th, 2012, 04:28 AM
  5. my run program does not work
    By rman27bn in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 16th, 2009, 09:13 AM