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 4 of 4

Thread: Java coding (Assignment)

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java coding (Assignment)

    I am currently coding for my assignment but i am having this problem.

    Add new item
    ============
    Category ( 1 - Manga 2 - Anime 3-Video Game) : 
     
    1
     
    (blank line) 
     
    Title :

    ........
    There is a blank line before the input of next data and i am wondering on how to remove the blank line.

    Below is my code :

    System.out.print("Category ( 1 - Manga 2 - Anime 3 - Video Game) : "); 
      int option = input.nextInt();
      while(!matching)
      {
         if ((option == 1) || (option == 2) || (option == 3))
         {
            category[itemCount] = categoryTypes[input.nextInt()-1];
            matching = true;
         }
         else
         {
            System.out.println("Invalid category , Please enter again");
            System.out.print("Category ( 1 - Manga 2 - Anime 3-Video Game) : "); 
            option = input.nextInt();
         }
      }
      input.nextLine();
      System.out.print("Title : ");
      titles[itemCount] = input.nextLine();
    }


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Java coding (Assignment)

    It most likely depends upon where and when you call the Scanner class for user input and what the user enters.
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java coding (Assignment)

    i don`t quite understand what you meant.

  4. #4
    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: Java coding (Assignment)

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

    I don't understand the problem. Show a sample run (copy it from the console and paste into a post) that has the undesired blank line.

    Ooops. I see that now in Post #1. Let me play with it.

    I think it's being caused by this line:

    category[itemCount] = categoryTypes[input.nextInt()-1];

    Why are you getting more input? Did you mean instead:

    category[itemCount] = categoryTypes[option-1];

Similar Threads

  1. HW problem. Trying to finish up the coding for this assignment
    By hodnee in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 12th, 2014, 03:28 AM
  2. Help with Coding School Assignment
    By mattmattmatt in forum Loops & Control Statements
    Replies: 12
    Last Post: October 8th, 2013, 09:11 PM
  3. Replies: 2
    Last Post: February 19th, 2012, 07:36 AM
  4. Java coding help
    By Javalover1 in forum The Cafe
    Replies: 0
    Last Post: April 12th, 2010, 08:11 PM
  5. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM

Tags for this Thread