2013-02-10 79 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后面只有一行,可以去掉大括号。