java programming using while loop or arrays
I but a picture that have the answers for problem one if you want to use it to help me with problem 2
In Problem 2, you will expand upon what you did in Problem 1. First, read the input and build the grid in the same way as you did earlier (feel free to use Problem 1 's code as a starting point'). For this problem, the program should determine whether one of the following situations has been found: (1) the game is a draw (2) the game is won by player 1 , or (3) the game is won by player 2 A game of Tic-Tac-Toe is won by a given player when a player places three marks in a row. For this problem, your program should determine whether three marks are placed in either a row along the horizontal axis, or a column along the vertical axis. Note: We do NOT consider the diagonals for this problem!
You will receive the following as input: - The name of the player (e.g.. Player1) - The grid index that the player decides to place their mark (e.g., 6 would be the right-middle space on the board) The above input is read in repeatedly until you see a \( -1 \) (which would be your sentinal value, or the value that terminates the input).
1. Read each turn taken by the player to place the marks on the grid, just like before 2. Determine whether 3 of the same marks are placed in either a row or a column 3. Display the Tic-Tac-Toe grid 4. Display one of the possible game results: Either it was a draw: A win for player 1 : Or a win for player 2: Hints Remember, there are plenty of ways to solve most problems in programming, and this problem is no exception! Of course, there is the most basic and brute-force solution of checking each of the 3 rows and each of the 3 columns manually. However, I encourage you to try a more advanced solution! Any working and reasonable solution will be accepted, but it's in your best interest to think outside the box! Perhaps calculating the product of each row and column could help you?:)
Input Output Player 11 Player25 120 Player14 120 Player22 100 Player 17 Game Over-Player 1 Wins Player2 - 1 Player 15 Player2 1 Player 12 211 \begin{tabular}{ll} Player24 & 210 \\ \hline \end{tabular} Player27 Player 1-1
\( \begin{array}{ll}\text { Player } 19 & 000 \\ \text { Player24 } & 200 \\ \text { Player 1-1 } & 001 \\ & \text { Game Over-Draw }\end{array} \) Player1 1 Player25 111 Player12 222 Player26 000 Player13 Game Over - Player 1 Wins Player2-1
publie stitf void main(Stivingli artali | int 1] board nem int[y]: String 7nput = sranebiratextL Ine (3): steingi player - inguts \( [\mathrm{e}] \); int \( P 1 \) - interer, parselnt (inpats [1]) : board [?1 \( -1]= \) t board \( [P 1-1]=27 \) inqut - searder a nextitivet); inguts = thatat. splte \( (*-) \) ? ptayer = inputis[0]7 P1 = Integer +parselnt inputs \( [1]\} \); disgilayboned (toard) : static void displayboned (int [] toonrd) ( tint count \( = \) if coantit 7 if (count \( =3 \) = \( = \) in de) : Systes, out. jic inctaf): 1) Problem 1: Tic-Tac-Toe Grid Problem Description an \( X \) of an \( \mathrm{O} \) in one of the fines spaces in the grid. The first plivert to inake a grtting the boand set up and regdy. The way we rele ance eacts setcen of the grid is shown belown