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: New to Java, need help with arrays inside a loop please!

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question New to Java, need help with arrays inside a loop please!

    I'm coding a program that will take the prices entered by a user at a store and display them back within the program, so far I've completed the entire program except the part that takes the users input within a loops and prints it out as a array.

    What I need help with;

    The program has parameters whether ie. Adding anything over 3000 doesn't work, add a 0 removes the last price, and a -1 ends the program.

    After ending the program (using -1) I need to take the prices the user input and output it within an array, example:

    Enter a price for item #5: $-1
    -1 entered, calculating total owing…
    OK Gary, your purchases are:
    $19.99
    $12.50
    $17.43
    $78.33
    SUB-TOTAL: $128.25

    I don't know how to code an array so I take reprint the prices entered by the user within the loop, if anyone could help me I'd be greatly appreciated.


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

    Default Re: New to Java, need help with arrays inside a loop please!

    Ok, so is your problem about creating the array or looping through the array at the end and printing out each element?
    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/

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: New to Java, need help with arrays inside a loop please!

    My problem is looping through the array at the end and printing it out.

    The array I created is : ArrayList <Double> costList = new ArrayList<Double>(15);
    double [] priceArray = new double [15];

    The max amount of items that can go though is 15.

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

    Default Re: New to Java, need help with arrays inside a loop please!

    What is in costList and what is in priceArray? Also, what have you already tried to do?
    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/

Similar Threads

  1. Can I have an if statement inside a while loop? or something similar?
    By ColeTrain in forum Java Theory & Questions
    Replies: 3
    Last Post: October 3rd, 2012, 05:01 PM
  2. Timer inside loop
    By dove in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 26th, 2012, 09:57 AM
  3. Switch statement inside a for loop need help.
    By TheWhopper858 in forum Loops & Control Statements
    Replies: 1
    Last Post: November 12th, 2011, 11:50 PM
  4. Retrieving arrays of java class inside C++ code
    By sattu in forum Java Native Interface
    Replies: 2
    Last Post: May 20th, 2011, 02:15 AM
  5. Adding array elements inside a loop
    By Scotty in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 28th, 2010, 09:48 PM