We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › adding up the value of array contents
Page Index Toggle Pages: 1
adding up the value of array contents? (Read 299 times)
adding up the value of array contents?
Aug 8th, 2008, 8:12pm
 
hello,

Pretty simple question, but I'm having a bit of trouble figuring it out ...
I've got a series of Arrays with a random set of 0's and 1's ....
I'd like to be able to get the overall value of each array (counting up the number of 1's) and return that integer...

Easy ways to do this?

cheers
Re: adding up the value of array contents?
Reply #1 - Aug 8th, 2008, 9:24pm
 
int sum = 0;
for(int i=0; i<array.length; i++)
 sum += array[i];
println(sum);
Page Index Toggle Pages: 1