I\'m having problems with this code. I don\'t want to look at others, so I\'m wondering what\'s wrong with mine.
If we list all the natural numbers below 10 that are mu
You should do:
for (int i = 0; i < 1000; i++) {
if (i % 3 == 0 || i % 5 ==0) {
temp += i;
}
}
This will add each number only one time. In your code, you will add 15 twice, since it'll be satisfied in both conditions in both loops.
Also note that according to the requirements, you should loop to < 1000
, not <=
.