Java Reference
In-Depth Information
26
if
(board[i][j].equals(" "))
27 board[i][j] = player;
28 }
29
30 /**
31
Creates a string representation of the
board, such as
32
|x o|
33
| x |
34
| o|.
35 @return
the string representation
36 */
37
public
String toString()
38 {
39 String r =
""
;
40
for
(
int
i =
0
; i < ROWS; i++)
41 {
42 r = r +
"|"
;
43
for
(
int
j =
0
; j < COLUMNS; j++)
44 r = r + board[i][j];
45 r = r +
"|\n"
;
46 }
47
return
r;
48 }
49
50
private
String[][] board;
51
private static final int
ROWS =
3
;
52
private static final int
COLUMNS =
3
;
53 }
307
308
ch07/twodim/TicTacToeRunner.java
1
import
java.util. Scanner;
2
3 /**
4
This program runs a TicTacToe game. It
prompts the
5
user to set positions on the board and
prints out the
6
result.
7 */
8
public class
TicTacToeRunner
9 {
10
public static void
main(String[] args)
11 {