Question

In a game of tic-tac-toe, two players take turns
marking an available cell in a 3 x 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 a tic-tac-toe game.
The program prompts two players to alternately enter an X token and O token.
Whenever a token is entered, the program redisplays the board on the console and
determines the status of the game (win, draw, or continue). Here is a sample run:

Enter a row (0, 1, or 2) for player X: 1 JEnter
Enter a column (0, 1, or 2) for player X: 1 -Enter
| X |
Enter a row (0, 1, or 2) for player 0: 1 JEnter
Enter a column (0, 1, or 2) for player 0: 2 JEnter
|X |0 |
Enter a row (0, 1, or 2) for player X:
| X |
|0|X| 0 |
хI
X player won
Expand
Transcribed Image Text

Enter a row (0, 1, or 2) for player X: 1 JEnter Enter a column (0, 1, or 2) for player X: 1 -Enter | X | Enter a row (0, 1, or 2) for player 0: 1 JEnter Enter a column (0, 1, or 2) for player 0: 2 JEnter |X |0 | Enter a row (0, 1, or 2) for player X: | X | |0|X| 0 | хI X player won

Expert Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Java

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: Write a program that prompts the user to input a string. The program then uses the function substr t...

A: 1. Prompt the user to input a string. 2. Use 'substr' function to remove all the vowels from the str...

Q: Multimedia services have two components of video and voice data. Can you characterize them as non–re...

A: Both the components of multimedia service uses real-time traffic. some characteristics of the transm...

Q: Discuss the current and future database technologies challenge?

A: Current database technology challenges are as follows: Data volume increases day by day and the bus...

Q: Given the declaration:char name[30];mark the following statements as valid or invalid. If a statemen...

A: To solve this question, let us first understand the declaration statement which states that : char n...

Q: Create a table of Sorting Algorithms for use as a personal reference or to use if you were explainin...

A: The following table that describes the sorting algorithms with their benefits and usage: Sorting ...

Q: Develop an Object-Oriented design for the following image. (What classes would you define? What prop...

A: Python code for vending machine:  *The program gives product, price, code, shelf to the user. def ve...

Q: Write a class called Fraction.java; this class will be designed to handlefractions. The Fraction cla...

A: Below is the required Java program: - Approach: - Import the essential package. Define the class Fr...

Q: Describe the purpose of a semaphore in the cooperation between two or more processes

A: SEMAPHORE: It is a variable in operating system which is used to manage the number of processes whi...

Q: Please with steps. Step by step

A: CFG: CFG stands for Context Free Grammar. In this grammar, each and every production rule present i...

Q: Hierarchical database has advantages over relational database. Discuss the given statement positivel...

A: Hierarchical database: - In this type of data model, the data is structured in a tree-like structure...

Q: PLEASE ANSWER ALL QUESTIONS AND SHOW AND EXPLAIN STEPS THANK YOU. PLEASE I NEED THIS ASAP.

A:   First let’s see What is Minimum Spanning Tree? A minimum spanning tree is a spanning tree for a we...

Q: Charles Hart, an accounts payable clerk, is an hourly employee. He never works a minute past 5 P.M. ...

A: Keeping the Company's data Safe is of utmost importance. Setting up an Embezzlement Scheme from home...

Q: Define loop control variable.

A: A loop control variable is a variable whose value determines whether a program exits a loop or conti...

Q: : A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design a class, poin...

A: Note: Since, programming language is not mentioned in the question, we will answer this question in ...

Q: Modify the program below and add a public method called isZero() to the Fraction class. This method ...

A: CODE: import java.util.ArrayList; import java.util.Scanner;   //Define the class Fraction class Frac...

Q: The equal sign (=) is known as the __________. a. equality symbol b. assignment operator c. equality...

A: Assignment operator: The symbol “=” is known as an assignment operator. It assigns the values that ...

Q: Take two time inputs from a user. And tell the differences between the time. Sample output Enter hou...

A: As the programming language is not mentioned so I am using C++ language to solve a question. Program...

Q: Explain Between Python and java

A: Parameter Python Java Code It has fewer lines of code. It has longer lines of code. Framework It...

Q: Consider the following definition of a class.class displayClass{public: void print(); ... private: i...

A: Part (a): The function prototype to overload the assignment operator (=) for the class “displayClass...

Q: Q: Write an Arduino sketch (code) along with the comments to display the temperature data from a tem...

A: Introduction: Arduino supports multiple platform languages. We can use functions from C, C++ and ja...

Q: Write the main steps of computational thinking

A: Computational thinking Computational thinking is a set of problem solving method that involves expr...

Q: What is displayed when the following style is applied to the HTML below? A) Choice A B) Choice B C) ...

A: According to the coding snippet provided in the snapshot, we are considering one container element d...

Q: What is the last value of A and Sum after executing the following C++ statements int A = 7, Sum=3; A...

A: Correct option is -015  

Q: Which procedure in the link library displays “Press [Enter] to continue. . .” and waits for theuser ...

A: Explanation: The WaitMsg procedure is used in JavaScript that displays a message when waiting for a...

Q: The SQL like operator is case sensitive (in most systems), but the lower() function on strings can b...

A: 1.  The lower function converts a string to lower-case. 2.  We need to write a query to find departm...

Q: What type of mistake is usually caused by a misspelled keyword, a missing punctuation character, or ...

A: Every programming language has a set of rules available to write the line of codes in that language....

Q: A __________ is a storage location in memory that is represented by a name. a. mnemonic b. data type...

A: A variable is basically a small storage area in the memory that is represented by the name.  

Q: 11) Which of the following is true about variables in JavaScript?A) A global variable at the top of ...

A: A variable declared inside the function is not obtainable or accessible outside the scope of the fun...

Q: Explain the client-centric consistency models ?

A: Client centric consistency model Client centric consistency model is used to provide a system wide ...

Q: What is the usage of QWORD type?

A: QWORD type: QWORD is one of the intrinsic data types used in assembly language. It declares the dat...

Q: True or False When a variable is declared in the initialization expression of a for loop, the scope ...

A: for loop: The “for” loop is designed for situations that require a counter variable. The counter va...

Q: Briefly explain data label

A: A data label is an integral part of a chart that that helps in hinting the data or information holdi...

Q: Look at the following declaration:enum Flower { Rose, Daisy, Petunia } Write a statement that declar...

A: Statement that declares a variable of the enumerated type: Below statement that declares a variable ...

Q: How many times will the MessageBox.Show method in the following code beprocessed?For intCount As Int...

A: MessageBox class is a method of C# of programming language It displays a message in the message box....

Q: Instructions Write a program that allows the user to enter the last names of five candidates in a lo...

A: Below is the required C++ program: - Approach: - Import the header files and use the namespace std ...

Q: A program has to be copied into what type of memory each time the CPU executes it?

A: A program has to be copied into the Main memory or RAM (random access memory) every time the CPU run...

Q: An informal language that has no syntax rules and is not meant to be compiled or executed is called ...

A: Discussion about the given terms: Faux code: An action written in the informal languagePseudocode: I...

Q: Give Description for Error code 04.

A: Error code 04 is basically an error responsive code of credit card transaction.

Q: PLEASE ANSWER ALL QUESTIONS AND SHOW AND EXPLAIN STEPS THANK YOU. PLEASE I NEED THIS ASAP.

A: First note down all the edges in the ascending order of their weights which is used to construct a m...

Q: What types of privileges are available in Oracle 12c? Define each type

A: When a database has multiple accesses, then it is important to ensure control of authorized accesses...

Q: List at least two features found in the Intel P965 Express chipset.

A: Chipset: Chipset is defined as a group of integrated circuits that are designed to work together to ...