0

I have some problems with the code below. I am receiving input using InputSreamReader,BufferReader. I am getting an error message that states.

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

Keep in mind that the code is not finished> I am just tring to determine what I am missing to get this error to dissapear.

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

3 Answers 3

2

One issue I see is, you have method inside another method. Move findMin definition outside main method.

Sign up to request clarification or add additional context in comments.

Comments

0

If this is an actual line in your code:

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

then take note that single-line comments start with // and no spaces are allowed between the two slashes. The parser will not ignore the above line and will give you errors.

Comments

0

There are 2 issues in this code,

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.