求助写个关于fibonacci数列的程序。

huangchao2005 2005-07-22 10:23:23
要有界面的。
...全文
45 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
huangchao2005 2005-07-22
  • 打赏
  • 举报
回复
牛人 这么快 谢谢!!
ainterpol 2005-07-22
  • 打赏
  • 举报
回复
/*
* Created on 2005-7-22
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class FibonacciTest extends JApplet implements ActionListener {

JLabel numLabel, resultLabel;
JTextField num, result;

public void init()
{
Container c = getContentPane();
c.setLayout( new FlowLayout());
numLabel = new JLabel ( " Enter integer and press Enter" );
c.add(numLabel);

num = new JTextField ( 10 );
num.addActionListener( this );
c.add( num );

resultLabel = new JLabel ( "Fibonacci Value is" );
c.add(resultLabel);

result = new JTextField ( 15 );
result.setEditable( false );
c.add ( result );

}

public void actionPerformed ( ActionEvent e )
{
long number, fibonacciValue;

number = Long.parseLong(num.getText());
showStatus( "Calculating...");
fibonacciValue = fibonacci( number );
showStatus( "done.");
result.setText( Long.toString(fibonacciValue));


}

public long fibonacci (long n)
{
if( n == 0 || n == 1 )
return n;
else
return fibonacci( n - 1 ) + fibonacci( n - 2 );



}

}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧