
/> //Using three arrays, each with three elements that represent the status of a completed tic-tac-toe game, print out the winning symbol (X or O) or if it was a draw game.
public class TicTacToe
{
public static void main(String[] args)
{
//true = X
//false = O
boolean[] row1 = {true, false, false};
boolean[] row2 = {false, true, false};
boolean[] row3 = {true, false, true};
if
(
(row1[0] && row1[1] && row1[2]) ||
(row2[0] && row2[1] && row2[2]) ||
(row3[0] && row3[1] && row3[2]) ||
(row1[0] && row2[0] && row3[0]) ||
(row1[1] && row2[1] && row3[1]) ||
(row1[2] && row2[2] && row3[2]) ||
(row1[0] && row2[1] && row3[2]) ||
(row3[0] && row2[1] && row1[2])
)
System.out.println("X Wins!");
else if
(
(!row1[0] && !row1[1] && !row1[2]) ||
(!row2[0] && !row2[1] && !row2[2]) ||
(!row3[0] && !row3[1] && !row3[2]) ||
(!row1[0] && !row2[0] && !row3[0]) ||
(!row1[1] && !row2[1] && !row3[1]) ||
(!row1[2] && !row2[2] && !row3[2]) ||
(!row1[0] && !row2[1] && !row3[2]) ||
(!row3[0] && !row2[1] && !row1[2])
)
System.out.println("O Wins!");
else
System.out.println("It's a cat's game");
}
}
?>