int turnCounter = 0;
public String [][] board = new String[3][3];
public static int buttonClicked = 0;
//this is going to check if there is a winning move
public String winningCheck(){
if (board[0][0] ==(board[0][1])
&& board[0][0]==(board[0][2])){
message = (board[0][0] + " is the winner");
gameOver = true;
}
return message;
}
if (xTurn == true && twoIsChosen == false && gameOver == false){
board[0][1] = "X";
b01.setText(board[0][1]);
if(turnCounter > 3){
winningCheck();
notification.setText(message);
}
xTurn = false;
notification.setText("O, it's your turn.");
twoIsChosen = true;
turnCounter++;
}
if (xTurn == true && threeIsChosen == false && gameOver == false){
board[0][2] = "X";
b02.setText(board[0][2]);
if(turnCounter > 3){
winningCheck();
notification.setText(message);
}
xTurn = false;
notification.setText("O, it's your turn.");
threeIsChosen = true;
turnCounter++;
}
if (xTurn == true && oneIsChosen == false && gameOver == false){
board[0][0] = "X";
b00.setText(board[0][0]);
if(turnCounter > 3){
winningCheck();
notification.setText(message);
}
xTurn = false;
notification.setText("O, it's your turn.");
oneIsChosen = true;
turnCounter++;
}
我想比較數組[0] [0]中的內容與數組[0] [1]和數組[0] [2],它們都是相同的,他們打印的佔位符是獲勝者,冠軍。當我運行程序時,字符串「X」進入數組,但我無法讓它們相互比較。什麼方法最好?我試過.equals()方法和.compareto()方法,但我仍然無法獲得任何工作。如何比較java中的二維數組的2個元素?
字符串是** **不相比較''==(除非你需要比較的身份。使用['equals()'](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#equals(java.lang.Object))方法代替 – 2014-11-14 22:35:15
可能的重複[如何比較Java中的字符串?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – 2014-11-14 22:35:51
您是否嘗試過調試應用程序? – 2014-11-14 22:43:01