星期一, 12月 19, 2005

"Lab 12-12-2005 (2) Static Class" (請病假)補po

//副程式
public class Fibonacci {
public static double f0=1,f1=1,f2=0;
public static double next()
{
f2=f0+f1;
f0=f1;
f1=f2;
return f2;
}
}

//主程式
public class main {
public static void main(String[] args)
{
for(int i=0;i<100;i++)
{
Fibonacci.next();
System.out.println("F(" + (i + 2) + ") = " + f2);
}
}
}

0 Comments:

張貼留言

<< Home