0

so i wrote this recursion program that uses memoization to calculate the fibonacci numbers. it's supposed to scan a user inputted number, call the method, check to see if the number is in the array, if not store it, ad increment the counter. so i should end up with the value plus the number of calls. i hope i'm on the right track.... thanks

```
public class memofib
{
static int[] list;
static int count= 0;
public static void main(String[] args)
{
int fib;
int n;
Scanner scan = new Scanner(System.in);
System.out.println("input a number");
n = scan.nextInt();
System.out.println("result: " + calcFib(n) + " calls: " + count);
}
public static int calcFib (int n)
{
list = new int[100];
count++;
if(n<2)
{
int ans = n;
return ans;
}
else
{
int ans = calcFib(n-1) + calcFib(n-2);
if(list.contains (ans))
{
return ans;
}
else
{
list[ans] = ans;
return ans;
}
if(n<2)
{
int ans = n;
return ans;
}
else
{
int ans = calcFib(n-1) + calcFib(n-2);
if(list.contains (ans))
{
return ans;
}
else
{
list[ans] = ans;
return ans;
}
}
}
}
```

*Edited 3 Years Ago by mike_2000_17*: Fixed formatting