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
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center