Skip to content

Instantly share code, notes, and snippets.

@jonasbjork
Created June 29, 2009 07:16
Show Gist options
  • Save jonasbjork/137510 to your computer and use it in GitHub Desktop.
Save jonasbjork/137510 to your computer and use it in GitHub Desktop.
/**
* Euler2.java
*
* @author jonas
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int sum = 2;
int a = 1;
int b = 2;
int c = 0;
while(a < 4000000) {
c = a+b;
a = b;
b = c;
if(c%2 == 0) {
sum += c;
}
System.out.print(".");
}
System.out.println("Sum: " + sum);
// var tredje tal är jämt.
a = 1;
b = 2;
c = 0;
sum = 0;
while(sum < 4000000) {
sum += b;
c = a + b;
a = b + c;
b = a + c;
System.out.print(".");
}
System.out.println("Sum: " + sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment