Created
August 2, 2016 17:09
-
-
Save nerzid/d421ed19f32753ddce3b03de2b3f1440 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
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