Topic: 大家帮我看以下java代码,这些错误该如何解决?谢谢

  Print this page

1.大家帮我看以下java代码,这些错误该如何解决?谢谢 Copy to clipboard
Posted by: cpp
Posted on: 2005-06-24 12:02


import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class FibonacciSerial extends Applet implements ActionListener
{
Label prompt = new Label("请输入菲波那契数列的长度(最大为10): ");
TextField input = new TextField(5);
String[] msg = new String[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[i] = "";
}

public void paint(Graphics g )
{
for(int i = 0; i<RequireCnt + ReturnCnt +1; i++)
g.drawString(msg[i],10, 40+15*i);
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource() ==input)
{
RequireCnt = 0;
ReturnCnt = 0;
if(Integer.parseInt(input.getText()) > 10)
{
prompt.setText("Too Large!");
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) +
"Return" + n ;
return n;
}
else
{
temp = Fibonacci(n-1) + Fibonacci(n-2);   //递归计算
ReturnCnt ++;
msg[RequireCnt + ReturnCnt] = Blanks(RequireCnt, ReturnCnt-1) +
"Return" + temp ;
return temp;
}
}

String Blanks(int stepIn, int stepBack)
{
String blank= "";

for(int i=0; i<(stepIn- stepBack); i++)
blank = blank+"";
return blank;
}

}

编译发生错误如下 该如何解决?
FibonacciSerial.java:8: illegal character: \12288
String[] msg = new String[50];      
^
FibonacciSerial.java:8: illegal character: \12288
String[] msg = new String[50];     
^
FibonacciSerial.java:8: illegal character: \12288
String[] msg = new String[50];       ^
FibonacciSerial.java:8: illegal character: \12288
String[] msg = new String[50];       ^
FibonacciSerial.java:8: illegal character: \12288
String[] msg = new String[50];       ^
FibonacciSerial.java:8: illegal character: \12288
String[] msg = new String[50];       ^
FibonacciSerial.java:9: <identifier> expected
int RequireCnt = 0;
^
FibonacciSerial.java:60: illegal character: \12288
temp = Fibonacci(n-1) + Fibonacci(n-2);   
^
FibonacciSerial.java:60: illegal character: \12288
temp = Fibonacci(n-1) + Fibonacci(n-2);   
^
FibonacciSerial.java:60: illegal character: \12288
temp = Fibonacci(n-1) + Fibonacci(n-2);   
^
10 errors

2.Re:大家帮我看以下java代码,这些错误该如何解决?谢谢 [Re: cpp] Copy to clipboard
Posted by: why
Posted on: 2005-06-24 12:19

trim the trailing spaces (Chinese character?) of these 2 statements
String[] msg = new String[50];
(i.e. after String[50]Wink
temp = Fibonacci(n-1) + Fibonacci(n-2);   //递归计算
(between ; and //递归计算)


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923