I am using Project Euler to test myself on the Java programming that I am teaching myself and here is problem one: 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.
Here is my Java attempt at calculating it
I get 26333 as the answer but when I enter that at projecteuler.net it says incorrect.public class problemOne { public static void main(String[] args) { int count; int sum = 0; //Multiples of 3 for(count = 0; count < 1000; count += 3){ System.out.println("count is: " + count); sum = sum + count; } //Multiples of 5 for(count = 0; count < 1000; count += 5){ System.out.println("count is: " + count); sum = sum + count; } System.out.println("Total is: " + sum); } }
Is there an error in the logic that I used to calculate? If so, where is it so I can rethink it.