Created
September 6, 2012 22:58
-
-
Save brunoperezm/3661065 to your computer and use it in GitHub Desktop.
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.
This file contains 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
/* 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. */ | |
public class Problema_EULER_1{ | |
public static void main (String[] args) { | |
int sum_3 = 0, | |
sum_5 = 0; | |
for (int x =1; x<=1000; x++) { | |
if ( (x*3) < 1000) { | |
sum_3 += (x*3); | |
} | |
if ( (x*5) < 1000 ) { | |
sum_5 += (x*5); | |
} | |
System.out.println((x*3) + " " + (x*5) + " " + sum_3 + " " + sum_5); | |
} | |
System.out.println(sum_3); | |
System.out.println(sum_5); | |
System.out.println(sum_3+sum_5); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment