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
Some certain conditions occurs where both conditions satisfies for 3 as well as 5 also. like when i=15 satisfies for both 15%3==0 and 15%5==0. so probably your answer is more than expected because you tried for both 3 and 5 separately. by doing this during these certain conditions you add repeated values. Hence it is better to check in single loop. like this -
for(int i=0 ; i<1000 ; i++)
{
if(i%3==0 || i%5==0)
{
temp = temp + i;
}
System.out.println(temp);
}