我正在用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;
}
最佳答案
您缺少{
括号
for(Cell col : row) { // <--- add this guy
result += col;
}
<小时/>
考虑学习使用 IDE。 IDE 几乎会立即指出这些错误。 它还会发现所有其他语法错误。
关于java - Java 中的 Tic Tac Toe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19525947/