Results 1 to 4 of 4
Thread: Sum up elements in an array?
- 05-28-2012, 05:26 AM #1
Sum up elements in an array?
How do I sum up all values of an array with for loop? And how do I find the average?
For example:
How do I sum up all the elements in that array?Java Code:int[] testResults = {80, 82, 62, 49, 16, 18};
Can anyone give me an example of the code and some explanation. Thanks
- 05-28-2012, 08:11 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Re: Sum up elements in an array?
Can you define an int variable that can hold the sum? Can you loop over your array?
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-28-2012, 08:15 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Re: Sum up elements in an array?
- 05-30-2012, 04:23 PM #4
Member
- Join Date
- May 2012
- Posts
- 16
- Rep Power
- 0
Similar Threads
-
searching one elements of array into another array???
By hacikho in forum New To JavaReplies: 3Last Post: 11-25-2011, 12:38 AM -
keep the first N elements of an array only
By aneuryzma in forum New To JavaReplies: 13Last Post: 03-27-2011, 04:03 PM -
sum of elements in array
By myst in forum New To JavaReplies: 7Last Post: 07-17-2010, 08:36 AM -
comparing array elements
By Jeremy720 in forum New To JavaReplies: 2Last Post: 10-13-2008, 02:33 AM -
Help with array of elements
By zoe in forum New To JavaReplies: 1Last Post: 07-24-2007, 05:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks