Skip to content

Instantly share code, notes, and snippets.

@goyuninfo
Last active August 29, 2015 14:01
Show Gist options
  • Save goyuninfo/9d3b762474104ddb0004 to your computer and use it in GitHub Desktop.
Save goyuninfo/9d3b762474104ddb0004 to your computer and use it in GitHub Desktop.
Project eluler problem 2 Even Fibonacci numbers
package euler;
/**
* @author <a href="http://i88.ca">http://i88.ca</a>
*
*/
public class P2 {
public static void main(String[] args) {
int a = 1;
int b = 1;
int c = a + b;
int sum = 0;
while (c < 4000000) {
// only c is even. a and b are always odd.
sum += c;
a = b + c;
b = c + a;
c = a + b;
}
System.out.println(sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment