Last active
August 20, 2017 15:13
-
-
Save Rijen/8766fbb7dd5cd797ee1cca18029a353f to your computer and use it in GitHub Desktop.
PL JAVA: 1.9
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 class Fibonacci { | |
static final int MAX_NUMBERS = 10; | |
public static void main(String[] args) { | |
FibonacciItem[] fibonacciItems = new FibonacciItem[MAX_NUMBERS]; | |
fibonacciItems[0] = new FibonacciItem(1); | |
fibonacciItems[1] = new FibonacciItem(1); | |
for (int i = 2; i < MAX_NUMBERS; i++) { | |
fibonacciItems[i] = new FibonacciItem( | |
fibonacciItems[i - 1].number + fibonacciItems[i - 2].number); | |
} | |
for (int i = 0; i < fibonacciItems.length; i++) { | |
fibonacciItems[i].print(); | |
} | |
} | |
} | |
class FibonacciItem { | |
public int number; | |
FibonacciItem(int number) { | |
this.number = number; | |
} | |
boolean is_even() { | |
return this.number % 2 == 0; | |
} | |
public void print() { | |
System.out.format("%8d%s%n", number, is_even() ? "*" : ""); | |
} | |
} | |
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
1 | |
1 | |
2* | |
3 | |
5 | |
8* | |
13 | |
21 | |
34* | |
55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment