Created
June 29, 2009 07:16
-
-
Save jonasbjork/137510 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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