Question

In: Computer Science

I am having an issue with the Java program with a tic tac toe. it isn't...

I am having an issue with the Java program with a tic tac toe. it isn't a game. user puts in the array and it prints out this. 1. Write a method print that will take a two dimensional character array as input, and print the content of the array. This two dimensional character array represents a Tic Tac Toe game. 2. Write a main method that creates several arrays and calls the print method. Below is an example of my main method: System.out.println("First Tic Tac Toe: " ); char[][] ttt1 = { {'X','O','X'}, {'0','O','X'}, {'X','X','O'}}; print(ttt1); System.out.println("Second Tic Tac Toe: " ); char[][] ttt2 = { {'O','O','X'}, {'0','O','X'}, {'X','X','O'}}; print(ttt2); here is the instructions my java program is all messed up. Please help.

Solutions

Expert Solution

Since no information is provided regarding the format of the output, I have written the code according to my understanding only. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// TicTacToe.java

public class TicTacToe {

      // required method

      static void print(char board[][]) {

            // looping through each row

            for (int i = 0; i < board.length; i++) {

                  // looping through each column

                  for (int j = 0; j < board[0].length; j++) {

                        // printing current character with a field with of 2, followed

                        // by a white space

                        System.out.printf("%2c ", board[i][j]);

                  }

                  //line break

                  System.out.println();

            }

      }

      public static void main(String[] args) {

            System.out.println("First Tic Tac Toe: ");

            char[][] ttt1 = { { 'X', 'O', 'X' }, { '0', 'O', 'X' },

                        { 'X', 'X', 'O' } };

            print(ttt1);

            System.out.println("Second Tic Tac Toe: ");

            char[][] ttt2 = { { 'O', 'O', 'X' }, { '0', 'O', 'X' },

                        { 'X', 'X', 'O' } };

            print(ttt2);

      }

}

/*OUTPUT*/

First Tic Tac Toe:

X O X

0 O X

X X O

Second Tic Tac Toe:

O O X

0 O X

X X O


Related Solutions

Write a program that plays tic-tac-toe. The tic-tac-toe game is played on a 3 × 3...
Write a program that plays tic-tac-toe. The tic-tac-toe game is played on a 3 × 3 grid as shown below: The game is played by two players, who take turns. The first player marks moves with a circle, the second with a cross. The player who has formed a horizontal, vertical, or diagonal sequence of three marks wins. Your program should draw the game board, ask the user for the coordinates of the next mark (their move), change the players...
In C# A Tic Tac Toe program that uses functions and arrays. The program should start...
In C# A Tic Tac Toe program that uses functions and arrays. The program should start by asking the player one for their name and then player two for their name. Then should print the board and ask the user what column and then what row they would like to put their x (or o, depending on the player) . Use the clear function to make it look as though the board is never repeating.. Thanks!
Perk Company produces three products: Tic, Tac, and Toe. Tic requires 90 machine setups, Tac requires...
Perk Company produces three products: Tic, Tac, and Toe. Tic requires 90 machine setups, Tac requires 80 setups, and Toe requires 330 setups. Berk has identified an activity cost pool with allocated overhead of $18,000 for which the cost driver is machine setups. How much overhead is assigned to the Tic product?
How to make tic tac toe game in javascript with vue.js
How to make tic tac toe game in javascript with vue.js
Develop a very simple Tic Tac Toe gaming software in Java. Ifyou want, you may...
Develop a very simple Tic Tac Toe gaming software in Java. If you want, you may take some code (with proper reference to the source from where it is taken - i.e., hackerrank or github) from an existing game implementation to extend/improve the functionalities. To develop a good quality software, you would like to follow a particular software engineering process or more than one process (waterfall, incremental, agile etc.) and choose an appropriate programming language.
Python Code Needed Two-Player, Two-Dimensional Tic-Tac-Toe Write a script to play two-dimensional Tic-Tac-Toe between two human...
Python Code Needed Two-Player, Two-Dimensional Tic-Tac-Toe Write a script to play two-dimensional Tic-Tac-Toe between two human players who alternate entering their moves on the same computer. Create a 3-by-3 two-dimensional array. Each player indicates their moves by entering a pair of numbers representing the row and column indices of the square in which they want to place their mark, either an 'X' or an 'O'. When the first player moves, place an 'X' in the specified square. When the second...
Write a program that allows two players to play a game of tic-tac-toe. Use a two-dimensional...
Write a program that allows two players to play a game of tic-tac-toe. Use a two-dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: Displays the contents of the board array. Allows player 1 to select a location on the board for an X. The program should ask the user to enter the row...
explain a pseudocode for tic tac toe in c++ between a computer and a player in...
explain a pseudocode for tic tac toe in c++ between a computer and a player in words
Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. A...
Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. A tic-tac-toe board looks like a table of three rows and three columns partially or completely filled with the characters X and O. At any point, a cell of that table could be empty or could contain an X or an O. You should have one instance variable, a two-dimensional array of values representing the tic-tac-toe board. This game should involve one human player vs....
In a game of tic tac toe. How do you check if all the positions in...
In a game of tic tac toe. How do you check if all the positions in a double array are taken, the double arrays are used to store the x's and o's?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT