我的以下代码存在一些问题。我正在使用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方法之外。

10-01 21:32