Skip to content

Instantly share code, notes, and snippets.

@janoulle
Created December 19, 2011 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janoulle/1495500 to your computer and use it in GitHub Desktop.
Save janoulle/1495500 to your computer and use it in GitHub Desktop.
Problem 2 - Project Euler in Java by Jane Ullah
//Author: Jane Ullah
//Date: 12/19/2011
//Site: janetalkscode.com
long a1 = 0L, a2 = 1L;
long nextTerm = 0L;
long sumEvenTerms = 0L;
boolean fourMillionthReached = false;
while ( !fourMillionthReached ) {
if (nextTerm >= 4000000) {
fourMillionthReached = true;
}
else {
nextTerm = a1 + a2;
if (nextTerm%2 == 0){
sumEvenTerms += nextTerm;
}
a1 = a2;
a2 = nextTerm;
}
}
System.out.print("Even sum is: " + sumEvenTerms);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment