user3626304
user3626304

Reputation: 17

Why is this array not found

I don't know why this array is not found I'm trying to find a number that correspinds, but this doesn't work for some reason

public static int sortLevel(char level) 
{ 
    final char[] LEVEL = {'7', '1', '9', '8'};
    for (int index = 0; index < LEVEL.length; index++) 
    {
        if(LEVEL(index) == level) return index;
    }

    // error code for not found, should not be reached
    return -1;
}

it returns error

cannot find symbol -- method LEVEL(int)

okay,dat works, but I have another problem

So, I have a Course Class, and I don't know what this method accepts as a parameter, Any ideas as to how,

this is the name of the method

public int compareTo(Course otherCourse)

this is the method call

course1.compareTo()

what do I put inside the brackets

Upvotes: 0

Views: 129

Answers (3)

conFusl
conFusl

Reputation: 939

try to change it to

if(LEVEL[index] == level) return index;

Upvotes: 1

Anubian Noob
Anubian Noob

Reputation: 13596

This line is incorrect:

(LEVEL(index) == level)

Parenthesis are use to call methods (eg System.out.println()).

To access an array in Java, you use square brackets:

(LEVEL[index] == level)

Upvotes: 1

Justin Jasmann
Justin Jasmann

Reputation: 2353

Your brackets are wrong.

if(LEVEL(index) ...

should be

if(LEVEL[index]...

Upvotes: 1

Related Questions