Skip to content

Instantly share code, notes, and snippets.

@nerzid
Created August 2, 2016 17:09
Show Gist options
  • Save nerzid/d421ed19f32753ddce3b03de2b3f1440 to your computer and use it in GitHub Desktop.
Save nerzid/d421ed19f32753ddce3b03de2b3f1440 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
public class EvenFibonacciNumbers {
public static void main(String[] args) {
ArrayList<Integer> liste = new ArrayList<>();
// 1, 1, 2, 3, 5, 8 ...
int second_prev_numb = 1;
int first_prev_numb = 1;
for(int i = 0; i < 100; i++)
{
int newNumb = second_prev_numb + first_prev_numb;
second_prev_numb = first_prev_numb;
first_prev_numb = newNumb;
if(newNumb % 2 == 0)
liste.add(newNumb);
}
System.out.println(liste);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment