Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.