我正在用java写一个井字游戏。现在我目前停留在显示板方法上。我正在尝试创建的板上有 X 和 O 将进入的线条。我目前得到的错误是
TicTac2.java:56:错误:类型返回结果非法开始;^ TicTac2.java:56: 错误:';' 预期返回结果;
我会随着我遇到的小问题更新此代码。我喜欢这个网站,因为它很有帮助!无论如何,这是我的代码:
import java.util.*;
public class TicTac2{
//declare a constant variable
public enum Cell {E, X, O}; //this is an O, not 0
public Cell[][] board;
public static final int SIZE = 3; //size of each row and each column
public static void main(String[] args) {
displayBoard a = new displayBoard();
System.out.println(a);
}
//displayBoard method
public static void drawLine() {
for (int i = 0; i <= 4 * SIZE; i++) {
System.out.print("-");
}
System.out.println();
}
public static void displayBoard(char[][] board) {
drawLine();
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
SIZE[i][j] = Cell.E;
System.out.print("| " + board[i][j] + " ");
}
System.out.println("|");
drawLine();
}
System.out.println();
}
public String toString(){
String result = "";
for(Cell[] row : board) {
for(Cell col : row)
result += col;
}
result =+ "\n";
}
return result;
}