-6

修正できないエラーが発生しました。これらの行で約8つのエラーが発生します。

        if (weight [1] + weight[4] + weight[7] == twoWeights){
        if(weight[1]==0){
            return 1;

        else if (weight [4] == 0)
            return 4;

        else 
            return 7;

    }
    if (weight [2] + weight[5] + weight[8] == twoWeights){
        if(weight[2]==0)
            return 2;

        else if (weight [5] == 0)
            return 5;

        else 
            return 8;

    }
    if (weight [0] + weight[4] + weight[8] == twoWeights){
        if(weight[0]==0)
            return 0;

        else if (weight [4] == 0)
            return 4;

        else 
            return 8;

    }                       
    if (weight [2] + weight[4] + weight[6] == twoWeights){
        if(weight[2]==0)
            return 2;

        else if (weight [4] == 0)
            return 4;

        else 
            return 6;

    }                       
    return -1;
}

int getRandomSquare(){
    boolean gotEmptySquare = false;
    int selectedSquare = -1;

    do {
        selectedSquare = (int) (Math.random() * 9);
        if (squares[selectedSquare].getLabel().equals("")){
            gotEmptySquare = true;
        }
    }
    while (!gotEmptySquare);
        return selectedSquare;
    }
    void highlightWinner(int win1; int win2; int win3) {
        squares [win1].setBackground(Color.CYAN);
        squares [win2].setBackground(Color.CYAN);
        squares [win3].setBackground(Color.CYAN);
    }
    void endTheGame (){
        newGameButton.setEnabled(true);
        for(int i=0;i<9;i++){
            squares[i].setEnabled(false);
        }
    }
}

}

エラーは次のとおりです。

TicTacToe.java:213:'else' without'if' else if(weight [4] == 0)^

TicTacToe.java:256:';' 期待されるintgetRandomSquare(){^

TicTacToe.java:269:式の不正な開始voidhighlightWinner(int win1; int win2; int win3){^

TicTacToe.java:269:';' 期待されるvoidhighlightWinner(int win1; int win2; int win3){^

TicTacToe.java:269:';' 期待されるvoidhighlightWinner(int win1; int win2; int win3){^

TicTacToe.java:274:式の不正な開始void endTheGame(){^

TicTacToe.java:274:';' 予想されるvoidendTheGame(){^

4

2 に答える 2

2

上記のコードの 2 行目には余分な{

左中括弧を閉じていないため、 に変更if(weight[1]==0){します。if(weight[1]==0)この変更を行った後もエラーが表示される場合は、クラス全体を作成してください。中括弧を適切に開いたり閉じたりしていないと思われます。

于 2013-02-10T19:44:13.250 に答える
0
if(weight[1]==0){
    return 1;

else if (weight [4] == 0)
    return 4;

別の if/else if を開始する前に、中括弧を閉じる必要があります。または、if の後に 1 行しかない場合は、左中かっこを取り除きます。

于 2013-02-10T19:44:15.560 に答える