Project Euler Problem 1 Java Solution - Multiples of 3 and 5

The Project Euler is a good place to look for programming logic problems that we can try to solve and develop our skills. After we have developed some abilities in programming, we naturally want to try other problems. Project Euler have problems of varying difficulties, so it is a good place to go as we learn programming. In this post, we will try to show a solution to Euler Problem #1 with title - Multiples of 3 and 5.

Project Euler Problem #1 - Multiples of 3 and 5.

The problem number one statement for the Euler Project is given below.
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.
A simple implementation to achieve the solution is given below.
/**
 * A simple implementation to solve Euler Problem #1 - Multiples of 3 and 5.
 */
public class EulerProblemSolution {
    public static void main(String[] args) {
        int maxNumber = 1000;
        long answer = 0;
        for(int i = 1; i < maxNumber; i++) {
            if(i % 3 == 0 || i % 5 == 0) {
                answer += i;
            }
        }
        System.out.println(answer);
    }
}

This program outputs the answer to the problem which is:

233168