|
import java.applet.Applet;
import java.awt.*;
import java.awt.envent.*;
public class FibonacciSerial extends Applet implements ActionListener
{
Label prompt = new Label("请输入菲波那契数列的长度(最大为10)");
TextField input = new TextField(5);
String[] msg = new Striing[50];
int RequireCnt = 0;
int ReturnCnt = 0;
public void init()
{
add(prompt);
add(input);
input.addActionListener(this);
for(int i = 0;i<50;i++)
msg="";
}
public void paint(Graphics g)
{ for(int i=0;i<RequireCnt+RequireCnt+1;i++)
g.drawSrting(msg,10,40+50*i);
}
public void actionPeformed(ActionEvent e)
{ if(e.getSource()==input)
{RequireCnt=0;
ReturnCnt=0;
if(Integer.parseInt(input.gerText())>0)
{prompt.setText("输入的数据过大,请输入小于10的整数:");
input.setText("");}
}
else
Fibonacci(Integer.parseInt(input.getText()));
}
repaint();
}
long Fibonacci(int n)
{long temp;
RequireCnt++;
msg[RequireCnt+ReturnCnt]=Blanks(RequireCnt,ReturnCnt)+"Fibonacci("+n+"):";
if (n==0||n==1)
{ReturnCnt++
msg[RequireCnt+ReturnCnt]=Blanks(RequireCnt,ReturnCnt-1)+"返回"+n;
return n;
}
else
{temp= Fibonacci(n-1)+Fibonacci(n-2);
ReturnCnt++;
msg[RequireCnt+ReturnCnt]=Blanks(RequireCnt,ReturnCnt-1)+"返回"+temp;
return temp;
}
}
String Blanks(int stepIn,int stepBack)
{String bank="";
for(init i=0;i<(steoIn-stepBack);i++)
blank=blank+"";
return blank;
}
}
编译时 出现以下错误
FibonacciSerial.java:35: invalid method declaration; return
repaint();
^
FibonacciSerial.java:37: 'class' or 'interface' expected
long Fibonacci(int n)
^
FibonacciSerial.java:62: 'class' or 'interface' expected
}
^
FibonacciSerial.java:63: 'class' or 'interface' expected
^
4 errors |
|