I did not learn loops using for yet, so I solved this problem using while but I can't find the issue with my problem, sum should be 233168 apparently, and I am getting 234168 I simply cannot identify where I missed it.
Question: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
package net.projecteuler;
public class Problem01 {
public static void main(String[] args) {
int n, sum;
boolean notFinished = true;
n = 0;
sum = 0;
while(notFinished) {
if(n % 3 == 0 || n % 5 == 0) {
sum = (sum + n);
}
n = (n + 1);
if(n > 1000) {
notFinished = !true;
}
}
System.out.print("A soma dos números é " + sum);
}
}