Skip to content

Instantly share code, notes, and snippets.

@fivesmallq
Created May 4, 2014 10:15
Show Gist options
  • Save fivesmallq/6321e781023b1bab0ee7 to your computer and use it in GitHub Desktop.
Save fivesmallq/6321e781023b1bab0ee7 to your computer and use it in GitHub Desktop.
public class Fibonacci {
public static void main(String[] args) {
int result = 0;
int first = 0, second = 1;
int sum = 0;
for (;;) {
result = first + second;
if (result > 4000000) {
break;
}
if (result % 2 == 0) {
sum = sum + result;
}
first = second;
second = result;
}
System.out.println(sum);//4613732
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment