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: Loops: Taking the average of a list of numbers

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Loops: Taking the average of a list of numbers

    The problem states that I have to ask the user how many quizzes they have taken. We take the number of quizzes they enter and prompt the user that many times (ex: they say 3 quizzes, we have to have an input dialog box 3 times asking them for their grade, separately) and each dialog box is unique, meaning it says: Enter quiz grade 1: , Enter quiz grade 2: , Enter quiz grade 3.

    then i have to take all of their quiz grades and find the average.

    I have to use a loop, and maybe an if statement, if necessary.

    please help, I am stuck and can't think of anything. thanks


  2. #2
    Junior Member
    Join Date
    Feb 2013
    Posts
    1
    My Mood
    Lurking
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Loops: Taking the average of a list of numbers

    Use an array to store the data and use a loop to transverse through the array.
    Everything afterwards is pretty trivial.

  3. The Following User Says Thank You to Lemonade For This Useful Post:

    janeeatsdonuts (February 24th, 2013)

  4. #3
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Loops: Taking the average of a list of numbers

    Please show your current code attempt. Please tell us any problems you may be having with your code attempt. You will also want to have a look at the Java tutorials section on for loops. Also before writing code, write out pseudo code to think through the logic of the program, the steps that the program will have to take to solve the problem. Only then should you try to write code.

  5. The Following User Says Thank You to curmudgeon For This Useful Post:

    janeeatsdonuts (February 24th, 2013)

  6. #4
    Member
    Join Date
    Jan 2013
    Posts
    34
    My Mood
    Busy
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default Re: Loops: Taking the average of a list of numbers

    Well, first, think how you would solve this problem in real life. Your friend gives you 3 numbers, you calculate the average of them how you were taught in Math class. Then try to write the code for it.

Similar Threads

  1. get the average of the linked list
    By dolcce in forum Java Theory & Questions
    Replies: 8
    Last Post: October 24th, 2012, 12:36 AM
  2. Error with taking float numbers from an input dialog box.
    By deepcrimson76 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 26th, 2012, 12:58 PM
  3. Functions, real numbers and for loops
    By grimhildr in forum Loops & Control Statements
    Replies: 1
    Last Post: October 15th, 2011, 07:11 AM
  4. taking information from one array into another
    By Stn in forum Object Oriented Programming
    Replies: 1
    Last Post: January 18th, 2011, 11:56 AM
  5. Taking an element out of an array
    By SlckP in forum Collections and Generics
    Replies: 3
    Last Post: May 5th, 2010, 02:26 PM

Tags for this Thread