## alejalv

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;
}
}
}
}
``````

## alejalv

nevermind the first post, i had things out of order... i thinki put them i nthe correct order but i am still getting a compile error that says missing return statement. can anyone please help me out???

``````import java.util.Scanner;
public class memofib
{
static int[] list = new int[100];
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)
{

count++;
if(n<2)
{
int ans= n;
return ans;
}

else
{
if(n>2)
{
int ans= n;
if(list[ans]== ans)
return list[ans];
}

else
{
int ans = calcFib(n-1) + calcFib(n-2);
list[ans] = ans;
return ans;
}
}
}
}
``````