Skip to content

Instantly share code, notes, and snippets.

@afrieirham
Created January 26, 2019 07:10
Show Gist options
  • Save afrieirham/be8d3711ae7cdd922c3b8878beff5993 to your computer and use it in GitHub Desktop.
Save afrieirham/be8d3711ae7cdd922c3b8878beff5993 to your computer and use it in GitHub Desktop.
Solution to Project Euler #2
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