Fibonacci column item N and seek

  Java solving Fibonacci N items and columns, this is a lot to learn Java students will encounter, today I saw a leisure look programming ideas, recording the whole process of implementation; Fibonacci both shaped like columns 1 , 1,2,3,5,8,13 .. . The number of columns or the like, wherein the third from the start, followed by an equivalent of the first two and, in accordance with this rule, the first time may be conceivable to use a recursive implementation is provided as the first item N and N-1 entry plus N -2 item and the code that is implemented:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class Fibonacci {
public static int getFibonaci(int n) {
if (n == 1) {
return 0;
} else if (n == 2) {
return 1;
} else {
return getFibonaci(n - 1) + getFibonaci(n - 2);
}
}
public static void main(String[] args) {
for (int i = 2; i < 20; i++) {
System.out.print(getFibonaci(i) + " ");
}
}
}

Original: Big Box  Fibonacci column and find the first N terms


Guess you like

Origin www.cnblogs.com/petewell/p/11612243.html