forked from ghostmkg/programming-language
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fabo.java
31 lines (24 loc) · 808 Bytes
/
Fabo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class Fabo {
public static int fibonacciRecursion(int n,int[]arr){
/* if(n == 0){
return 0;
}
if(n == 1 || n == 2){
return 1;*/
if(n<=1){
return n;
}
if(arr[n]!=0){
return arr[n];
}
int ans=fibonacciRecursion(n-2,arr) + fibonacciRecursion(n-1,arr);
return arr[n]=ans;
}
public static void main(String args[]) {
int maxNumber = 6;
System.out.print("Fibonacci Series of " + maxNumber + " numbers: ");
int []arr=new int[maxNumber+1];
int ans=fibonacciRecursion(maxNumber,arr);
System.out.println(ans);
}
}