1
我的教授希望此代碼打印出Tic-Tac-Toe板,但我不完全確定從這裏做什麼。這是我已經試過:TicTacToe與2D陣列
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
char[][] board = new char[3][3];
boolean hasWinnerOrStaleMate = false;
while (!hasWinnerOrStaleMate) {
int row;
int col;
boolean setLocation = false;
do {
row = keyboard.nextInt();
col = keyboard.nextInt();
if (board[row][col] == '\u0000') // vacant
{
board[row][col] = 'X';
setLocation = true;
} else {
System.out.println("Occupied Try again");
}
} while (!setLocation);
for (row = 0; row < board.length; row++) {
for (col = 0; col < board.length; col++) {
System.out.print(board[row][col]);
}
}
}
}
是的,好吧,你至少*試過*什麼? – Veluria