// Sample class in preparation for TicTacToe program public class Test2D { // Method to count the symbols of type 'player' in the row with th // given index 'row'. public static int sumOfRow(char A[][], int row, char player) { int sum = 0; for (int col = 0; col < A.length; col++) { if (A[row][col] == player) sum++; } return sum; } public static void main(String args[]) { // defining a 2S array char A[][] = new char[10][10]; // initializing a 2D array for (int row = 0; row < A.length; row++) { for (int col = 0; col < A[row].length; col++) { A[row][col] = '-'; } } // setting some board pieces 'by hand' A[1][1] = 'O'; A[1][2] = 'X'; A[1][6] = 'O'; A[A.length-1][1] = 'O'; A[A.length-1][A.length-1] = 'X'; // print out 2D array, representing a ToicTacToe board System.out.println(); for (int row = 0; row < A.length; row++) { for (int col = 0; col < A[row].length; col++) { System.out.print(" " + A[row][col] + " "); } System.out.println(); } System.out.println(); // Testing the 'sumOfRow' method for different player symbols System.out.println("sum of 'o' in 2nd row = " + sumOfRow(A, 1, 'O')); System.out.println("sum of 'x' in last row = " + sumOfRow(A, A.length-1, 'X')); } }