gpt4 book ai didi

java - Java中斐波那契序列中的BufferedReader错误

转载 作者:行者123 更新时间:2023-12-02 11:04:23 24 4
gpt4 key购买 nike

我是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]);
}
}

请帮助。

最佳答案

Java区分大小写

n = Integer.parseInt(br.readline());
^

应该
n = Integer.parseInt(br.readLine());

关于java - Java中斐波那契序列中的BufferedReader错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22488240/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com