Skip to content

Instantly share code, notes, and snippets.

@iwhcoj
Created May 14, 2010 21:18
Show Gist options
  • Save iwhcoj/401686 to your computer and use it in GitHub Desktop.
Save iwhcoj/401686 to your computer and use it in GitHub Desktop.
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