FAQs on the exercise Declaration, Initialization, and Assignment
There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in #get-help.
Agree with a comment or answer? Like () to up-vote the contribution!
public class Exercise2 {
public static void main(String args) {
// Declare a 2d array of float values called floatTwoD
float[][] floatTwoD; // Since this is 2D. We can simply create the array with float which is the name of the datatype and 2 brackets infront followed by the name which is floatTwoD.
// Initialize the 2d array from the last step to an empty 2d array consisting of 4 arrays with 10 elements each
floatTwoD = new float[4][10]; // We have already initialize floatTwoD so there is no need to create it again, we can simply instantiate this with a new float datatype that has 4 rows and 10 columns.
// Declare and initialize an empty 2d array of integers consisting of 15 rows and 8 columns called dataChart
int[][] dataChart = new int[15][8]; Since this has a different datatype which is an integer. Lets rewrite the whole 2D array again with the given name and the new datatype and assign the value of row which is 15 and columns which has 8 values.
// Create a 2D char array called ticTacToe representing the provided tic-tac-toe board. Use the characters 'X', 'O', and ' '.
char[][] ticTacToe = new char[][] {{'X', 'O', 'O'},{'O', 'X', ' '}, {'X', ' ', 'X'}}; //First note this is a char datatype. So create your instance and followed by your characters as it shown on the board;
// When no one is looking, you want to modify the game to where you, 'O', wins the game. Replace the game board so that all X’s are O’s and all O’s are X’s. Do this in one line with initializer lists.
ticTacToe = new char[][]{{'O', 'X', 'X'},{'X', 'O', ' '}, {'O', ' ', 'O'}}; //Simply change your X values to O and O to X. So far as your using new here this will create a different Tictactoe with O will be the wins.
}
I’m stuck to the last exercise : " When no one is looking, you want to modify the game so 'O' wins. Replace the game board so that all X’s are O’s and all O’s are X’s. Do this in one line with initializer lists. Do not declare ticTacToe again."
Create a 2D char array called ticTacToe representing the provided tic-tac-toe board. Use the characters ‘X’, ‘O’, and ’ '.
char ticTacToe = new char { {‘X’, ‘O’, ‘O’}, {‘O’, ‘X’, ’ '}, {‘X’, ’ ', ‘X’} };
When no one is looking, you want to modify the game to where you, ‘O’, wins the game. Replace the game board so that all X’s are O’s and all O’s are X’s. Do this in one line with initializer lists.
I don’t see where you have replaced the X’s with O’s and vice versa. You created the ticTacToe array in Step 3. In Step 4, you are supposed to exchange the X’s and O’s.
For Example {'O', 'X', ' '} from Step 3 will become {'X', 'O', ' '} in Step 4.