Java中斐波那契序列中的BufferedReader错误
我是Java新手,来自C语言背景。在尝试实现斐波那契序列时,我收到以下错误:
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]);
}
}
请帮忙
# 1 楼答案
因为它应该是
readLine
而不是readline
。请记住JAVA是区分大小写的。请使用IDE,它甚至会在编译之前捕捉到这样的错误# 2 楼答案
Java区分大小写
应该是