Search⌘ K

Solution Review: Task I to III

Explore how to build a Tic-Tac-Toe game in Java by reviewing step-by-step solutions for initializing a 3x3 board, displaying it with nested loops, and tracking player turns using if-else statements. Understand the logic behind updating the board state as you prepare for your AP Computer Science exam.

Task I: Create a Tic-tac-toe board

The task was to create a 3x3 array to represent the Tic-tac-toe board.

Let’s review the solution for this task in the code playground below:

Java
class Main {
public static void main(String[] args) {
//Let's create a 3x3 character array that represents our tic tac toe board
char[][] game_board = new char[3][3];
}
}
  • Line 6: We create a 2D array named game_board that has 3 rows (the first square bracket) and 3 columns (the second square bracket).

We’ve ...