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: How can I loop this?

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How can I loop this?

    I need to be able to loop this so the user can input as many items as he/she wants and the quantity as well. He's my code:

    case 3:System.out.print("Enter Customer name");

    System.out.print("\n Enter the product: ");
    String product1=keyboard.next();

    System.out.print( "\n Enter the quantity of the product");
    int quantity1=keyboard.nextInt();


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

    Default Re: How can I loop this?

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Then put it in a loop. A while or do/while loop is a common solution.

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

    Default Re: How can I loop this?

    I'm still having trouble. I want the loop so the user can enter up to 5 different items and choose 5 different quantities.

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

    Default Re: How can I loop this?

    Show the loop you created that allowed the user to enter 5 items and choose 5 quantities. Since you know that the loop allows a specific number of choices, a for loop might be the simplest:

    for ( int choice = 1 ; choice <= 5 ; choice++ ) {}

    and then the body of the for loop will ask the user to enter 5 items and 5 quantities. Now show what you've tried.

Similar Threads

  1. loop once or loop multiple times
    By stanlj in forum Loops & Control Statements
    Replies: 3
    Last Post: November 7th, 2013, 02:14 PM
  2. help with when the for loop is met and i want to run the while loop again
    By m49er704 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 22nd, 2013, 09:03 AM
  3. For loop, the first command in the loop does not get executed the 2nd time..
    By lina_inverse in forum Loops & Control Statements
    Replies: 1
    Last Post: October 16th, 2012, 09:00 PM
  4. Converting a while loop to a for loop and a for loop to a while loop.
    By awesom in forum Loops & Control Statements
    Replies: 3
    Last Post: February 26th, 2012, 08:57 PM
  5. [SOLVED] My while loop has run into an infinite loop...?
    By kari4848 in forum Loops & Control Statements
    Replies: 3
    Last Post: March 1st, 2011, 12:05 PM