我收到无法修复的错误。我在这些行中收到大约 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' 没有 'if' else if (weight [4] == 0) ^
TicTacToe.java:256: ';' 预期 int getRandomSquare(){ ^
TicTacToe.java:269: 非法开始表达式 void highlightWinner(int win1; int win2; int win3) { ^
TicTacToe.java:269: ';' 预期 void highlightWinner(int win1; int win2; int win3) { ^
TicTacToe.java:269: ';' 预期 void highlightWinner(int win1; int win2; int win3) { ^
TicTacToe.java:274: 非法的表达式开头 void endTheGame (){ ^
TicTacToe.java:274: ';' 预期无效 endTheGame (){ ^