I am writing a tic tac toe game in java. Right now I am currently stuck on the display board method. The board I am trying to create has lines in which the X's and O's will go into. The error I am currently getting is
TicTac2.java:56: error: illegal start of type return result; ^ TicTac2.java:56: error: ';' expected return result;
I will update this code as I go along it with little problems I encounter. I love this site because it helps so much! Anyway here is my code:
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;
}
You are missing a {
bracket
for(Cell col : row) { // <--- add this guy
result += col;
}
Consider learning to use an IDE. An IDE will point out these errors almost immediately. It will also find all other syntax errors.