Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java Code If possible can we use char instead of string ? Also use the scanner in the main method not outside Problem Set: In
Java Code
If possible can we use char instead of string ?
Also use the scanner in the main method not outside
Problem Set: In a game of tic-tac-toe, two players take turns marking an available cell in a 3 3 grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A draw (no winner) occurs when all the cells on the grid have been filled with tokens and neither player has achieved a win. Create a program for playing tic-tac-toe. The program prompts two players to enter an X token and O token alternately. Whenever a token is entered, the program redisplays the board on the console and determines the status of the game (win, draw, or continue). See sample execution below. Note the output when a player tries to play a cell that is already occupied. Input The Row number, followed by the column number. Rows and columns are numbered 0-2 Output: The state of the game board and finally the winner. If the game ends in a tie, output should be displayed showing this as well. Below you will find all possible output statements. Note there are 3 spaces between the | . Enter a row (e, 1, or 2) for player X Enter a column (e, 1, or 2) for player X Enter a row (e, 1, or 2) for player 0 Enter a column (e, 1, or 2) for playero X player won O player won .This cell is already occupied. Try a different cell In Sample Execution Enter a row (e, 1, or 2) for player X1 Enter a column (e, 1, or 2) for player X: 1 Enter a row (e, 1, or 2) for player 0: Enter a column (e, 1, or 2) for player 0: 1 0 Enter a row (e, 1, or 2) for player X 0 Enter a column (e, 1, or 2) for player X: 0 Enter a row (e, 1, or 2) for player 0: 0 Enter a column (e, 1, or 2) for player 0: 0 This cel1 is already occupied. Try a different cell Enter a row (e, 1, or 2) for player 0:1 Enter a column (e, 1, or 2) for player 0: oIxI Enter a row (e, 1, or 2) for player X: 2 Enter a column (e, 1, or 2) for player X: 2 xIol olxI x player wonStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started