-2

我已经尝试了几次,这就是我目前所拥有的:

    public void turnOn(int index, spotlights[]){
    spotlights[index]=2;
    currentStatus=2;
    }

这是我的数组定义:

    private Spotlight[] spotlights = new Spotlight[20];

有二十盏灯,我将一个(索引)更改为 on 或 currentStatus 更改为 2。

我会很感激任何帮助,谢谢!

4

3 回答 3

3

尝试这个:

public void turnOn(int index, Spotlight[] spotlights)
于 2013-01-25T16:35:51.740 回答
1
public void turnOn(int index, Spotlight[] name){
    spotlights = name;
    spotlights[index]=2;
    currentStatus=2;
}

spotlights将数组传递给您的turnOn方法,或者您可以直接使用方法变量。

public void turnOn(int index, Spotlight[] spotlights){
        spotlights[index]=2;
        currentStatus=2;
    }
于 2013-01-25T16:36:04.830 回答
0

像这样使用:

public void turnOn(int index, Spotlight[] spotlights) {
    spotlights[index].setCurrentStatus(2);
}

请注意,您应该在类上有一个setCurrentStatus(int)方法。Spotlight

于 2013-01-25T16:36:31.607 回答