
Unknown error
Hi!
So I've been working on a program to find the sum of all the multiples of 3 or 5 below 1000.
Here is my code:
Code:
class AddAllMultiples{
public static void main (String[] args){
int addition = 0;
for(int i=0; i <= 1000; i++){
if((i % 3 == 0)  (i % 5 == 0)){
System.out.println(i);
i+=addition;
}
}
System.out.println("The total value is " + addition);
}
}
Every single time I get that the total value is 0. I checked and "i" is working fine, but somehow it is not adding to addition and every time "addition" is 0. I have spent a very long time on this please help!
Thanks!

Re: Unknown error
Try writing out the line "i+=addition" in full  ie without using the += operator.
Also you might want to review exactly what the += operator does. There is a description (under "The Arithmetic Operators") in the Assignment, Arithmetic and Unary Operators page of Oracle's Tutorial. Read what it says carefully.

Re: Unknown error
Ahh thank you. I had it completely backwards. It was doing i=i+addition, instead of addition=addition+i. (which is addition+=i)
Thanks again!

Re: Unknown error
You're welcome  I'm glad you've got it sorted out.