星期六, 5月 21, 2005

Answer to 5/20 Lab (Fibonacci Class)

public class StaticDemo
{
public static void main(String[] args)
{
for (int i = 3; i < 15; i++)
{
System.out.print("Fib( " + i + " )=" );
System.out.println(Fibonacci.next());
}
}
}


public class Fibonacci
{
private static int i=1;
private static int j=1;
private static int k;

public static int next()
{
k = i + j;
j = k;
i = j;
return k;
}
}

沒有留言: