In this video, I'm going to go through part one of our final challenge, part one consisted of setting
up a Tic-Tac taghrid by implementing two tasks.
Task one says, to create an array with three rows of underscore characters.
And looking back at the article, the tic tac toe board as three rows in each row has three elements.
So back in my code, I'll say car board.
Is equal to a new car array with three rows such that each euro has three elements.
And you know what, I was thinking of doing a nested loop that updates every element in each row, but
it would be easier to just initialize everything from the get go.
So all set are variable equal to a two tier array with three rows of values.
Such that each row stores three underscore characters.
Beautiful.
The next task is to print the array using a function called the print array.
So right over here, we'll create a function that's public static.
The function seems to be void.
It's called print board.
And it takes one parameter, the board.
And inside the function, I left you some instructions which will ensure that your board prints in a
nice format, No.
One print a new line, simple enough.
Now we'll say print, not print online.
The reason I'm using print, not print online, is because print online already adds a new line for
you.
So putting another end is going to create two lines.
So alternatively, you could just write print online with nothing inside, but I find that kind of weird.
Anyways, the next step is to print the board.
This requires a nested loop, we start with the outer loop or the Roman next is going to start at Rosero.
And it's going to keep running as long as the ROE index is less than the length of our 2D array.
In other words, as long as it's less than the number of rows I.
Plus plus.
And the inner loop is going to start at the first element in that row.
J equals zero.
It's going to keep running until J indexes every element in that row.
J plus plus.
And inside the inner loop, we can print the contents of our 2D array.
The first bracket is going to index each row.
And the second one indexes every element in that row.
I know we're not done yet, but before we finish coding the logic inside Prince Board, it's a good
idea to keep testing your code as you update it, because you never know when a bug is going to find
its way into your code.
So I'm going to call the function passing that to drasin argument.
Run the code.
And so far, everything works, but every Dasch character on your score, I should say, prince on the
same line.
Looking back at the instructions, it says, to separate each row by two lines of space.
So after the inner loop runs through an entire row, we're going to print two lines.
Then it says that each row proceeds a tab of space, so before printing each row, we need to add a
tab of spacing.
Run the code.
There is your type of spacing that gets printed before each row.
And notice that each arrow is separated by two empty lines.
And the last step says that each character in the grid has one space from the other character.
We can do just that.
Rewriting, running the code.
And I think it's safe to say that we're done.
I hope I clarified any problems you had with part one.
Good luck on part two.
I hope you figure it out.