Java 二维阵列天线
我的教授想让这段代码打印出一个Tic-Tac趾板,但我不完全确定接下来该怎么做。这就是我尝试过的:Java 二维阵列天线,java,Java,我的教授想让这段代码打印出一个Tic-Tac趾板,但我不完全确定接下来该怎么做。这就是我尝试过的: public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); char[][] board = new char[3][3]; boolean hasWinnerOrStaleMate = false; while (!hasWinnerOrStaleMat
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]);
}
}
}
}
publicstaticvoidmain(字符串[]args){
扫描仪键盘=新扫描仪(System.in);
字符[][]板=新字符[3][3];
布尔值haswinerorstalemate=false;
而(!haswinerorstalemate){
int行;
int col;
布尔setLocation=false;
做{
行=键盘.nextInt();
col=键盘.nextInt();
如果(线路板[行][col]='\u0000')//空闲
{
板[行][col]=“X”;
setLocation=true;
}否则{
System.out.println(“重试”);
}
}而(!setLocation);
用于(行=0;行
扫描仪是教授用来获取键盘字符的课程
如果您在循环中输入输入,您就玩了TIC-TAC-TOE的游戏:)给您一个提示:当您打印数组时,您应该在打印出一行之后再打印一行新行
for (row = 0; row < board.length; row++) {
for (col = 0; col < board.length; col++) {
System.out.print(board[row][col]);
}
System.out.println();
}
for(行=0;行
剩下的我留给读者作为练习。是的,你至少试过什么了吗?