2013-02-10 72 views
-5

我收到我無法修復的錯誤。我得到約8個錯誤在這些行:java applet的錯誤

 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: '別人' 沒有 '如果' 否則如果(重量[4 ] == 0) ^

TicTacToe.java:256:';'預期INT getRandomSquare(){ ^

TicTacToe.java:269:表達的非法起動空隙 highlightWinner(INT WIN1; INT WIN2; INT WIN3){^

TicTacToe.java:269: ';'預期的空虛highlightWinner(int win1; int win2; int win3){ ^

TicTacToe.java:269:';'預期空隙highlightWinner(INT WIN1; INT WIN2; INT WIN3){ ^

TicTacToe.java:274:表達空隙endTheGame的非法起動(){ ^

TicTacToe.java:274:「; 「預期空隙endTheGame(){ ^

+0

你必須更仔細地閱讀異常跟蹤,你將能夠解決所有問題。 – alnasfire 2013-02-10 19:48:16

回答

2

在上述第二行代碼有一個額外的{

變化if(weight[1]==0){if(weight[1]==0),因爲您不關閉開口支架。 如果您在進行此更改後仍然看到錯誤,請將整個班級提交。我懷疑你沒有正確打開或關閉大括號。

0
if(weight[1]==0){ 
    return 1; 

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

您需要先關閉花括號,然後才能啓動另一個if/else if。或者如果你在if後面只有一行,可以去掉大括號。