|
Febonic Series
Febonic Series
|
package com.bethecoder.tutorials.core.special_numbers;
public class FebonicSeries {
/**
* @param args
*/
public static void main(String[] args) {
printFebonicSeries(0, 1, 12);
printFebonicSeries(2, 4, 12);
printFebonicSeries(1, 5, 12);
}
public static void printFebonicSeries(int first, int second, int required) {
show(first); show(second);
//0 1 1 2 3 5 8 13 21 34
for (int i = 0 ; i < required ; i ++ ) {
show(first + second);
second = first + (first = second);
}
System.out.println();
}
private static void show(int num) {
System.out.print(num + " ");
}
}
|
| |
It gives the following output,
0 1 1 2 3 5 8 13 21 34 55 89 144 233
2 4 6 10 16 26 42 68 110 178 288 466 754 1220
1 5 6 11 17 28 45 73 118 191 309 500 809 1309
|
|