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

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.

    Note: This is the array I created at the beginning of my program..

    ArrayList <Double> costList = new ArrayList<Double>(15);
    double [] priceArray = new double [15];


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

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



    You mention array and yet in the code snippet you have an array and an ArrayList. Why?
    You need a loop that reads in the user input and stores it in the array. After user enters -1 to end input you need another loop that iterates over the array and prints out each value. You can sum them up in the same loop.
    Improving the world one idiot at a time!

Similar Threads

  1. New to Java, need help with arrays inside a loop please!
    By Darkaudicate in forum Java Theory & Questions
    Replies: 3
    Last Post: November 21st, 2012, 02:48 PM
  2. 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
  3. Timer inside loop
    By dove in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 26th, 2012, 09:57 AM
  4. 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
  5. 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