DynamicArray Class:
public class DynamicArray
{
private int[] fib;
public DynamicArray()
{
fib = new int[1];
}
public int get(int position)
{
if (position >= fib.length)
return 0;
else
return fib[position];
}
public void put(int position, int value)
{
if (position >= fib.length)
{
int newSize = 4 * fib.length;
if(position >= newSize)
newSize = 4 * position;
int[] newData = new int[newSize];
System.arraycopy(fib, 0, newData, 0, fib.length);
fib = newData;
System.out.println("Dynamic aray size changed to " + newSize);
}
fib[position] = value;
}
}
Fibonacci Series Class:
public class FibonacciSeries
{
public static void main(String[] args)
{
DynamicArray newDyn = new DynamicArray();
newDyn.put(0, 0);
newDyn.put(1, 1);
for(int i = 2; i <= 5; i++)
{
int a = newDyn.get(i);
int a1 = a - 1;
int b = newDyn.get(i);
int b1 = b - 2;
int c = a1 + b1;
newDyn.put(i, c);
int d = newDyn.get(i);
System.out.println(d);
}
}
}
Figured maybe a fresh pair of eyes could spot the problem. For now I'm going to sleep on it, and see what I come up with in the morning. Any help is appreciated thanks.

New Topic/Question
Reply


MultiQuote






|