Hey all! So I have written a basic tic-tac-toe game and all seems to be well except the board display. It should display as follows:
1 2 3
4 5 6
7 8 9
But is coming out 123456789.
For the life of me I can not figure out what I did wrong. Any hints or pointers would be appreciated greatly. Thanks!
Here is my code:
Look carefully at your boardDisplay method and understand what it's doing. For example, when would it start another line? Do you have code that does that? And why are you printing an empty string after the array element? An empty string does nothing to affect your display, so what's the point of including that in the expression passed to println()?
I would suggest you don't want those switch statements, which contain much repeated code. You only need to write one lot of code to find the square. Also using one lot of code is much less error‑prone. You use i % 3 to find the column and i / 3 to find the row, but that will only work if the top left square is No 0. If you use 1 for top left, you will have to use (i − 1) % 3 for column and (i − 1) / 3 for row instead. If you miss out the () it will go horribly wrong.
Why have you made all your methods static?
posted 3 years ago
I have been referencing the class book for most of this code. So that is why the static methods. It is just what the book shows. I have never used Java before and this is the 5th week of my course. So everything is still pretty new to me. Thanks for the help! It is appreciated.