Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that randomly fills in 0s and 1s into a 3x3 TicTacToe board, pri

ID: 3656214 • Letter: W

Question

Write a program that randomly fills in 0s and 1s into a 3x3 TicTacToe board, prints the board and also a message saying whether any rows, columns, or diagonals with all 0s or 1s. Use a two-dimensional array to represent a Tic Tac Toe board.


This is what I know, I just dont know how to put it together :

//(1) How to make a random number that is either 0 or 1:

public class TicTacToe{


public static void main(String[] args){

double zeroOrOne = Math.random() * 2;


//(2) How to create a 3x3 board:


int[][] board = new int[3][3];


//(3) How to iterate for row/column checks:


for ( int rc=0 ; rc<3 ; ++rc ) { // rc = row/column ID

int firstColVal = board[rc][0];

int firstRowVal = board[0][rc];


if ((board[rc][1] == firstColVal) && (board[rc][2] == firstColVal))

System.out.println("All " + firstColVal + "'s on column " + (rc+1));


if ((board[1][rc] == firstRowVal) && (board[2][rc] == firstRowVal))

System.out.println("All " + firstRowVal + "'s on row " + (rc+1));

}


}

}

Explanation / Answer

I'll help you with a few things: (1) How to make a random number that is either 0 or 1: int zeroOrOne = Math.random() * 2; (2) How to create a 3x3 board: int[][] board = new int[3][3]; (3) How to iterate for row/column checks: for ( int rc=0 ; rc
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote