something else is going on besides your loop not being reset. The fact that you have declared i and set it to start with 0 in the for condition should cause it to start fresh each time the method is called. Also, once the loop is started there does not appear to be anything that changes the value of i value other then each iteration of the loop.
Joined: Jun 29, 2009
The solution is to add sumWhole=0; as the first line of code.
Not sure why i dident try that first, instead of last...
Joined: May 13, 2009
ahhh, OK, that makes sense, I clearly missed the point of your original post.
Still, something doesn't feel right. the variable sumWhole is not declared within the method, so I guess it is an instance variable of the class this method is in.
Now, you are calling this method either from within this class, or from another class. Which is it?
So your method resets an instance variable each time it is called, then applies some math to it, then returns the instance variable, I guess there is a good reason for that, but it makes me think about taking a second look at how your variables are defined, maybe sumWhole should be a local variable?
Then again maybe it is ok, I guess it depends on the program.