我是Java新手,来自C背景。在尝试实现Fibonacci序列时,我收到以下错误:
error: cannot find symbol n = Integer.parseInt(br.readline()); ^ symbol: method readline() location: variable br of type BufferedReader
该计划如下:
import java.io.*;
public class fibonacci
{
public static void main(String args[])throws IOException
{
int n;
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(read);
System.out.println("enter the value of n");
n = Integer.parseInt(br.readline());
int fib[];
fib[1]=1;
fib[2]=1;
for(int i=3; i<=n; i++)
{
fib[i] = fib[i-1] + fib[i-2] ;
}
System.out.println("the"+n+"th fibonacci term is "+fib[n]);
}
}
请帮助。
答案 0 :(得分:0)
Java区分大小写
n = Integer.parseInt(br.readline());
^
应该是
n = Integer.parseInt(br.readLine());
答案 1 :(得分:0)
因为它应该是readLine
而不是readline
。请记住,JAVA具有案例敏感性。请使用IDE,即使在编译之前它也会遇到这样的错误。