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 8207127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:54:13+00:00 2026-06-07T08:54:13+00:00

I’m trying to input 3 different variables into an array inside a while loop,

  • 0

I’m trying to input 3 different variables into an array inside a while loop, as long as i don’t enter stop for any of the variables. the while loop is only suppose to let me input a second variable value if the 1st variable isn’t stop, and likewise with inputting a third variable value

Right now, the first loop goes fine and i can input all 3 variables, but the 2nd and 3rd time, the for loop outputs the first variable, but doesn’t allow me to input a value before skipping to the 2nd variable.
ex of what i mean:

  1. name:afasdf

  2. extra info:afdsaf

  3. unit cost:123123214

  4. name: extra info: adflskjflk
    also, entering Stop isn’t ending the loop either

  5. unit cost:123217

i know that this loop works when there’s only one variable, and i’ve tried using a for loop instead of a while loop, and adding tons and tons of else statements, but it seems to stay the same

is there something wrong with the way i set up my breakers?
is the way i set up the last breaker(the one that stops even when i put stop for a double variable) messing up the rest of hte loop?

thank you so much

here is my code

ArrayItem s = new ArrayItem(); 

String Name = null, ID = null;  
double Money = 0;

boolean breaker = false;
while(breaker ==false)
{
   System.out.print("Name:" + "\t");
   Name = Input.nextLine();

   if(Name.equals("Stop")) //see if the program should stop
       breaker = true;

   System.out.print("Extra Info:" + "\t");
   Details = Input.nextLine();

   if(ID.equals("Stop")) 
       breaker = true;

   System.out.print("Unit Cost:" + "\t");
   Money = Input.nextDouble();

   // suppose to let me stop even if i input stop
   //  when the variable is suppose to be a double
   if(Input.equals("stop") || Input.equals("stop"))
      breaker = true;
   else
      s.SetNames(Name);

   s.SetInfo(Details);
   s.SetCost(Money);
}
  • 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-06-07T08:54:15+00:00Added an answer on June 7, 2026 at 8:54 am

    A couple of things about the code: "Name:" + "\t" can be simplified ot "Name:\t". This is true for the rest of the code. In Java, it’s customary to use camelcase where the first word is lowercase. For example, s.SetMoney would be s.setMoney. Also, variables follow the same rules where Money would be money, and ID would be id. If your teacher is teaching you otherwise, then follow their style.

    The loop should also be a do-while loop:

    do
    {
        // read each value in sequence, and then check to see if you should stop
        // you can/should simplify this into a function that returns the object
        // that returns null if the value should stop (requiring a capital D
        // double for the return type)
    
        if ( /* reason to stop */)
        {
            break;
        }
    
        s.setNames(name);
        s.setId(id);
        s.setMoney(money);
    
    } while (true);
    
    private String getString(Scanner input)
    {
        String result = input.nextLine();
    
        // look for STOP
        if (result.equalsIgnoreCase("stop"))
        {
            result = null;
        }
    
        return result;
    }
    
    private Double getDouble(Scanner input)
    {
        Double result = null;
        // read the line is a string looking for STOP
        String line = getString(input);
    
        // null if it's STOP
        if (line != null)
        {
            try
            {
                result = Double.parseDouble(line);
            }
            catch (NumberFormatException e)
            {
                // not a valid number, but not STOP either!
            }
        }
    
        return result;
    }
    

    There are a lot of concepts in there, but they should help as you progress. I’ll let you put the pieces together.

    Also, you did need to fix the brackets, but that’s not the only issue. Because Money is a double, you must read the value as a String. I suspect that Input is a Scanner object, so you can check Input.hasNextDouble() if it’s not, then you can conditionally check the String value to see if it’s “stop” (note: you are checking for “Stop” and “stop”, which are not equal). Your last, no-chances check compares the Scanner to “stop”, which will never be true. Check

    System.out.print("Unit Cost:\t");
    
    if (Input.hasNextDouble())
    {
        Money = Input.nextDouble();
    
        // you can now set your object
        // ...
    }
    // it's not a double; look for "stop"
    else if (Input.nextLine().equalsIgnoreCase("stop"))
    {
        // exit loop
        break;
    }
    
    // NOTE: if it's NOT a double or stop, then you have NOT exited
    //       and you have not set money
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

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.