for loop
Sat May 20 2023 14:32:12 GMT+0000 (Coordinated Universal Time)
Saved by
@gokulz
import java.util.Scanner;
public class TicTacToe{
static Scanner sc = new Scanner(System.in); // the scanner class can access by all the methods
public static void main(String[] args) {
// create a 2d character array full of dashes
char[][] board = {{'-','-','-'},
{'-','-','-'},
{'-','-','-'}
};
for(int i=0; i<9; i++){
if(i%2==0){
System.out.println("Turn: X");
int[] spot = askUser(board);
board[spot[0]][spot[1]] = 'X';
printBoard(board);
}
else{
System.out.println("Turn: O");
int[] spot = askUser(board);
board[spot[0]][spot[1]] = 'O';
printBoard(board);
}
content_copyCOPY
Comments