Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Project Euler problem one

1. ## Project Euler problem one

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
```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);
}
}```
I get 26333 as the answer but when I enter that at projecteuler.net it says incorrect.
Is there an error in the logic that I used to calculate? If so, where is it so I can rethink it.

2. ## Re: Project Euler problem one

You're forgetting that some numbers are multiples of *both* 3 and 5, and you are in effect adding these numbers *twice*.

3. ## Re: Project Euler problem one

Originally Posted by curmudgeon
You're forgetting that some numbers are multiples of *both* 3 and 5, and you are in effect adding these numbers *twice*.
Thanks

4. ## Re: Project Euler problem one

I got it figured out! Now on to problem 2...