Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java: Complete the TicTacToeWinner method, which should look at a tic-tac-toe board & determine if there is a winner. (https://en.wikipedia.org/wiki/Tic-tac-toe) public class TicTacToe { //

Java:

Complete the TicTacToeWinner method, which should look at a tic-tac-toe board & determine if there is a winner. (https://en.wikipedia.org/wiki/Tic-tac-toe)

public class TicTacToe {

// Takes in a tic tac toe board

// returns 1 if 'X' wins

// returns 2 if 'O' wins

// returns 3 if it is a tie

// returns -1 if there is not yet a winner

public static int ticTacToeWinner(char[][] board) {

return -1;

}

public static void printBoard(char[][] board) {

for (int i = 0; i < 3; i++) {

for (int j = 0; j < 3; j++){

System.out.print(board[i][j] + "\t");

}

System.out.println(" ");

}

}

public static void main(String[] args) {

// note: a - indicates that a spot is currently empty

char[][] board = {{'O','-','X'},{'-','-','O'},{'-','X','-'}};

printBoard(board);

int winner = ticTacToeWinner(board);

if (winner == 1) {

System.out.println("X wins");

}

if (winner == 2) {

System.out.println("O wins");

}

if (winner == 3) {

System.out.println("Tie game");

}

if (winner == -1) {

System.out.println("Keep Playing");

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Development Of Knowledge Framework For Affective Content Analysis

Authors: Swarnangini Sinha

1st Edition

B0CQJ13WZ1, 979-8223977490

More Books

Students also viewed these Databases questions

Question

Identify three ways to manage an intergenerational workforce.

Answered: 1 week ago

Question

Prepare a Porters Five Forces analysis.

Answered: 1 week ago

Question

Analyze the impact of mergers and acquisitions on employees.

Answered: 1 week ago