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

Thread: How do you make a sum of variables in a loop?

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do you make a sum of variables in a loop?

    Well allow me to clarify, I've looped a method 14 times, each time it focuses on a different person and how many oranges he/she has eaten. I now want to calculate the total amount of oranges eaten and exactly how many oranges are eaten on average, how can I do that?? the amount of oranges eaten is variable, they are determined by what number the user types in.


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: How do you make a sum of variables in a loop?

    Let your method return the number of oranges and sum them up in the loop. You know/can count how often your loop runs. Calculate the average after the loop.

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

    Ada Lovelace (August 13th, 2014)

  4. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How do you make a sum of variables in a loop?

    Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

Similar Threads

  1. stuck trying to count sum of even and odd numbers for reading loop.
    By gio in forum Loops & Control Statements
    Replies: 2
    Last Post: February 21st, 2013, 11:23 AM
  2. Why do we make variables of a class private?
    By Pratyush in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 1st, 2013, 02:26 AM
  3. Question about for loop to print the sum of series of fractions
    By _K_ in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 17th, 2012, 08:08 AM
  4. Replies: 2
    Last Post: October 5th, 2012, 01:14 PM
  5. Help with accumulating sum values in do while loop
    By steel55677 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 19th, 2011, 11:01 PM