Lab 12-12-2005 (2) Static Class
package welcome;
import javax.swing.JOptionPane;
public class Lab_Fibonacci
{
public static double f1=1,f2=1,f3=0;
public static void main(String[] args)
{
String num_str = JOptionPane.showInputDialog("Enter the items number n :");
System.out.println( Lab_Fibonacci.next(num_str) );
System.exit(0);
}
public static double next(String num_str)
{
int n = Integer.parseInt(num_str);
for ( double i=1;i<=n;i++ )
{
f3 = f1 + f2;
f1 = f2;
f2 = f3;
}
return f3;
}
}
0 Comments:
張貼留言
<< Home