0

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

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;
        }
    }
4

3 回答 3

2

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

于 2013-11-05T21:56:06.447 回答
0

这段代码有2个问题,

1. Declare your findMin method outside your main.
2. Remove the space between / / and should be // This method finds the smallest number in an array looking at indexes startIndex and endIndex
于 2013-11-05T22:02:34.203 回答
0

如果这是您的代码中的实际行:

/ / This method finds the smallest number in an array looking at indexes startIndex and endIndex

然后注意单行注释以 开头,//两个斜杠之间不允许有空格。解析器不会忽略上面的行并且会给你错误。

于 2013-11-05T21:59:10.817 回答