Created
November 5, 2014 21:05
-
-
Save Buzz-Lightyear/1a4fcb5fe30e9f66f8d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Project Euler Question 1: | |
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. | |
Display the sum of all the multiples of 3 or 5 below 1000. | |
*/ | |
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
class ProjectEulerProblem1 | |
{ | |
public static void main (String[] args) throws java.lang.Exception | |
{ | |
int sum = 0; | |
for(int i = 3; i < 1000; i += 3) | |
sum += i; | |
for(int i = 5; i < 1000; i += 5) | |
sum += i; | |
for(int i = 15; i < 1000; i += 15) | |
sum -= i; | |
System.out.println(sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment