looping and adding numbers
I am trying to write a method that traverses a for loop
each time I traverse the loop I am taking a number from an array
I need to add all these numbers up at the end, or add to a variable each time the loop is traversed so it increases by the number.
I am struggling with syntax on this one.
I have tried
grandtotal = + total;
I thought this may add total each time the loop is traversed, but it didnt
The only other way I can think is either always knowing the previous numbers value and then adding that, or being able to find the number sum total an ArrayList object.
Is there a tried and tested way to do this? I've search everywhere and can find no examples even remotely similar.
whoops I just seem to have answered my own question, it was
grandtotal += total;
I knew posting a question up would make it happen one way or another
grandTotal += total; is just a simplified way of writing
grandTotal = grandTotal + total;
If the shorthand way ever confuses you, just use the longhand way
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL