Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6980741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:03:56+00:00 2026-05-27T18:03:56+00:00

I have a college assignment where I need to print out items sold by

  • 0

I have a college assignment where I need to print out items sold by a hardware store, take input from a user, perform some calculations on that input, and then print out an invoice.

I have been able to successfully print out the items sold by the hardware store, but am encountering problems with the while loop that takes the input.

The program asks the user to enter a CODE and then asks for the corresponding QUANTITY. This works fine on the first iteration of the loop, but on the second iteration the user prompts for “CODE:” and “QUANTITY:” appear on the same line, despite my use of println when prompting the user.

I would greatly appreciate a detailed response appropriate for someone new in programming.

Here’s the code:

 import java.util.Scanner;

 class HardwareStore {


    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);


        System.out.println("WELCOME TO THE HARDWARE STORE!");
        System.out.println("----------------------------------------------------------------------");


        String sticky = "G22";
        String keyring = "K13";
        String screwy = "S21";
        String padlock = "I30";


        int stickyprice = 10989;
        int keyringprice = 5655;
        int screwyprice = 1099;
        int padlockprice = 4005;


        System.out.println("CODE\t\tDESCRIPTION\t\t\t\t\tPRICE");
        System.out.println("----\t\t-----------\t\t\t\t\t-----");

        System.out.println(sticky + "\t\tSTICKY Construction Glue, Heavy Duty, \n\t\t7oz, 12 Pack \t\t\t\t\t$" + stickyprice);
        System.out.println(keyring + "\t\tCAR-LO Key Ring, Quick Release, \n\t\t1 Pack\t\t\t\t\t\t$ " + keyringprice);
        System.out.println(screwy + "\t\t!GREAT DEAL! SCREW-DUP Screwy Screws, \n\t\tDry Wall Screws, 3 in. Long, 50 Pack\t\t$ " + screwyprice);
        System.out.println(padlock + "\t\tLET-IT-RAIN, Weather Proof Padlock, \n\t\tPortable, One Push Functionality\t\t$ " + padlockprice);
        System.out.println("----------------------------------------------------------------------");


        int i = 10000; 
        String [] usercode = new String[i]; 
        int [] userquantity = new int[i];


        System.out.println("PLEASE ENTER YOUR ORDER:");


        while (true) {
            System.out.println("CODE: (X to terminate)");
            usercode[i] = in.nextLine();

            if (usercode[i].equalsIgnoreCase("x")) {
                break;
            }

            System.out.println("QUANTITY: ");
            userquantity[i] = in.nextInt();
        } 
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:03:57+00:00Added an answer on May 27, 2026 at 6:03 pm

    when you enter the QUANTITY you’re pressing enter. That newline character isn’t used by in.nextInt();, it remains in the scanner buffer, until you roll around to in.nextLine() again.

    At that point in.nextLine() reads until it finds a newline character, which just happens to be the next one in the buffer. So it skips straight to QUANTITY again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For an assignment in college, we have to make a script in Perl that
I have a college project where I need to extend an existing spreadsheet application
I have the following code that I am working on for my college assignment.
For a college assignment I need to run an experiment related to MySQL. I
I have an assignment to be done in college, a piece asks for the
I'm doing a college assignment in XNA to make a virtual piano. I have
I have an assignment in college in which we are required to read in
I have been working on a college C assignment, and have been trying to
I am a student in college and have an assignment which requires finding large
I have a little bit of experience in c/c++ from college but have not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.