Created
May 14, 2010 21:18
-
-
Save iwhcoj/401686 to your computer and use it in GitHub Desktop.
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
public class euler1 | |
{ | |
public static void main(String[]args) | |
{ | |
int sum=0; | |
for (int i=1; i<1000; i++) | |
{ | |
if (i%3==0 || i%5==0) | |
sum+=i; | |
} | |
System.out.println("The sum of all multiples of 3 & 5 under 1000 is "+sum); | |
} | |
} | |
// | |
public class euler2 | |
{ | |
public static void main(String[]args) | |
{ | |
int [] fibo = new int [100]; | |
for (int i=0; i<=50; i++) | |
{ | |
if (i==0 || i==1) | |
fibo [i] = i; | |
else fibo [i]= fibo [(i-2)] + fibo [(i-1)]; | |
if (fibo [i]>=4000000) | |
break; | |
} | |
int sum=0; | |
for (int i=0; i<50; i++) | |
{ | |
if (fibo [i]>=4000000) | |
break; | |
if ((fibo [i])%2==0) | |
sum+=fibo[i]; | |
} | |
System.out.println(sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment