gpt4 book ai didi

java - 递归和数组

转载 作者:行者123 更新时间:2023-12-02 06:34:25 25 4
gpt4 key购买 nike

我对下面的代码有一些问题。我正在使用 InputSreamReaderBufferReader 接收输入。我收到一条错误消息,指出。

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
Illegal modifier for parameter findMin; only final is permitted

Syntax error on token "(", ; expected
Syntax error on token ",", ; expected
Syntax error on token ",", ; expected
Syntax error on token ")", ; expected

请记住,代码尚未完成>我只是想确定我缺少什么以使此错误消失。

public static void main(String[] args) throws IOException
{
double [] numbers = new double[100];

InputStreamReader streamR = new InputStreamReader(System.in);
BufferedReader inFile = new BufferedReader(streamR);
String reader = inFile.readLine();
/ / This method finds the smallest number in an array looking at indexes startIndex and endIndex
public static double findMin(double[] elements, int startIndex, int endIndex)
{
if (endIndex == startIndex) // base case
{
return elements[endIndex];
}
else // recursive case to compare the min found so far
{
double previousMin = findMin(elements, startIndex, endIndex-1);
if (previousMin > elements[endIndex])
return elements[endIndex];
else
return previousMin;
}
}

最佳答案

我看到的一个问题是,你在另一个方法中有方法。将 findMin 定义移到 main 方法之外。

关于java - 递归和数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19799810/

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