A simple Tic Tac Toe game played in the terminal. Players take turns placing X and O on a 3x3 grid by entering numbers 1-9. The game automatically detects wins, draws, and handles invalid inputs.
cd tic-tac-toe
javac src/App.java
java -cp src AppWelcome to Tic Tac Toe!
|---|---|---|
| 1 | 2 | 3 |
|-----------|
| 4 | 5 | 6 |
|-----------|
| 7 | 8 | 9 |
|---|---|---|
X goes first. Enter a number (1-9) to place X:
1
|---|---|---|
| X | 2 | 3 |
|-----------|
| 4 | 5 | 6 |
|-----------|
| 7 | 8 | 9 |
|---|---|---|
O's turn; enter a number (1-9) to place O:
2
|---|---|---|
| X | O | 3 |
|-----------|
| 4 | 5 | 6 |
|-----------|
| 7 | 8 | 9 |
|---|---|---|
X's turn; enter a number (1-9) to place X:
5
|---|---|---|
| X | O | 3 |
|-----------|
| 4 | X | 6 |
|-----------|
| 7 | 8 | 9 |
|---|---|---|
O's turn; enter a number (1-9) to place O:
3
|---|---|---|
| X | O | O |
|-----------|
| 4 | X | 6 |
|-----------|
| 7 | 8 | 9 |
|---|---|---|
X's turn; enter a number (1-9) to place X:
9
|---|---|---|
| X | O | O |
|-----------|
| 4 | X | 6 |
|-----------|
| 7 | 8 | X |
|---|---|---|
Congratulations! X wins! Thanks for playing.