Created
January 26, 2019 07:10
-
-
Save afrieirham/be8d3711ae7cdd922c3b8878beff5993 to your computer and use it in GitHub Desktop.
Solution to Project Euler #2
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
public static void problem2(){ | |
int a = 1; | |
int b = 2; | |
int c = 0; | |
List<Integer> even = new ArrayList<Integer>(); | |
do{ | |
c = a + b; | |
if(b%2==0){ | |
even.add(b); | |
} | |
a = b; | |
b = c; | |
}while(c<4000000); | |
System.out.println(Arrays.toString(even.toArray())); | |
Integer[] numbers = even.toArray(new Integer[even.size()]); | |
int total = 0; | |
for(int i=0; i<numbers.length; i++){ | |
total += numbers[i]; | |
} | |
System.out.println(total); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment