Method call expected when writing an array

185 Views Asked by At
public class test {
public static void main(String[] args) {
    double[] d=new double[500];
    for (int i = 0; i <500 ; i++) {
        d[i]= Integer.MAX_VALUE;
    }
    boolean[] disco=new boolean[500];
    for (int i = 0; i <500 ; i++) {
        disco[i]= false;
    }
    disco(5)=true;
}

}

I get an "method call expected" error when trying to change a value in the disco array. Could someone explain to me why that is?

2

There are 2 best solutions below

0
bhspencer On

To access an item in an array at a particular position use the square brackets notation.

disco[5]=false;

not

disco(5)=false;
0
MMelvin0581 On

You should use disco[5] not disco(5).

When you put () after disco, java is looking for a method disco that does not exist. To access an index of an array, you use [], square brackets.