Question: thingy.txt - Notepad File Edit Format View Help // Tic-Tac-Toe Game. import java.util.*; public class thingy{ static String[] board; static String turn; // CheckWinner

![java.util.*; public class thingy{ static String[] board; static String turn; // CheckWinner](https://s3.amazonaws.com/si.experts.images/answers/2024/02/65bc6d24255d5_52465bc6d2407f6b.jpg)



![= board [0] + board[1] + board [2]; break; case 1: line](https://s3.amazonaws.com/si.experts.images/answers/2024/02/65bc6d2734e2f_52765bc6d2715f5a.jpg)
![= board [3] + board[4] + board [5]; break. Ln 1. Col](https://s3.amazonaws.com/si.experts.images/answers/2024/02/65bc6d27ed3ec_52765bc6d27d1134.jpg)
thingy.txt - Notepad File Edit Format View Help // Tic-Tac-Toe Game. import java.util.*; public class thingy{ static String[] board; static String turn; // CheckWinner method will // decide the combination // of three box given below. static String checkWinner() { for (int a = 0; a < 8; a++) { String line = null; switch (a) { case 0: line = board [0] + board[1] + board [2]; break; case 1: line = board [3] + board[4] + board [5]; break. Ln 1. Col 1 100% Windows (CRLF) I UTF-8 X thingy.txt - Notepad File Edit Format View Help case 1: line = board [3] + board[4] + board [5]; break; case 2: line = board [6] + board [7] + board[8]; break; case 3: line board [0] + board[3] + board [6]; break; case 4: line board [1] + board [4] + board [7]; break; case 5: line = board [2] + board [5] + board [8]; break; case 6: line board [0] + board [4] + board [8]; break; case 7: line board [2] + board [4] + board [6]; break; } //For X winner if (line equals("XXX")) { Ln 1, Col 1 100% Windows (CRLF) UTF-8 X thingy.txt - Notepad File Edit Format View Help } //For X winner if (line.equals("XXX")) { return "X"; } // For 0 winner else if (line.equals("000")) { return "0"; } } for (int a = 0; a < 9; a++) { if (Arrays.asList (board). contains (String.valueOf(a + 1))) { break; } else if (a == 8) { return "draw"; } } // To enter the X Or 0 at the exact place on board. System.out.println(turn + "'s turn; enter a slot number to place " + turn + " in:"); return null. In 1 Col1 100% Windows (CRLF) I UTF-8 X thingy.txt - Notepad File Edit Format View Help } // To enter the X Or 0 at the exact place on board. System.out.println(turn + "'s turn; enter a slot number to place " + turn + " in:"); return null; // To print out the board. 4 | 5 | 6 */ static void printBoard() { System.out.println("|---|---|---|"); System.out.println("| " + board [0] + " System.out.println(" + board [2] + " ["); ["); System.out.println("| + board [3] + " | " + board [5] + " ["); --|"); System.out.println(" System.out.println("| "+ board [6] +"|" + board [7] " " + board [8] + " "); System.out.println("|---|---|---|"); " + board [1] + " + board [4]+"| Ln 1, Col 1 100% Windows (CRLF) UTF-8 X thingy.txt - Notepad File Edit Format View Help System.out.println("| " + board [6] + System.out.println("|---|---|---|"); } public static void main(String[] args) { Scanner in = new Scanner(System.in); board = new String [9]; turn = "X"; String winner = null; for (int a = 0; a < 9; a++) { } board [a] =String.valueOf(a + 1); System.out.println("Welcome to 3x3 Tic Tac Toe."); printBoard(); | " + board[7] + " | " + board [8] + " "); System.out.println("X will play first. Enter a slot number to place X in:"); while (winner == null) { int numInput; // Excention handling Ln 1, Col 1 100% Windows (CRLF) I UTF-8 thingy.txt - Notepad File Edit Format View Help // Exception handling. // numInput will take input from user like from 1 to 9. // If it is not in range from 1 to 9. // then it will show you an error "Invalid input." try { numInput = in.nextInt(); if (!(numInput > 0 && numInput thingy.txt - Notepad File Edit Format View Help board [numInput if (turn.equals("X")) { turn = "0"; } else { } 1] = turn; turn = "X"; } else { printBoard(); winner checkWinner(); System.out.println("Slot already taken; re-enter slot number: "); } // If no one win or lose from both player x and 0. // then here is the logic to print "draw". if (winner.equals IgnoreCase("draw")) { System.out.println("It's a draw! Thanks for playing."); } Ln 1. Col 1 100% Windows (CRLF) I UTF-8 thingy.txt - Notepad File Edit Format View Help } } } printBoard(); winner = checkWinner(); } else { } } System.out.println("Slot already taken; re-enter slot number: "); } // If no one win or lose from both player x and 0. // then here is the logic to print "draw". if (winner.equals IgnoreCase("draw")) { System.out.println("It's a draw! Thanks for playing."); } // For winner -to display Congratulations! message. else { System.out.println("Congratulations! " + winner + "'s have won! Thanks for playing."); In 1 Col1 100% Windows (CRLE) I UTF-8
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
