无法解决问题 "java: illegal start of expression"
Cant fix the problem "java: illegal start of expression"
我是 Java 的新手,正在尝试学习它,但我的代码中总是出现此错误“java:表达式的非法开始”,我不知道为什么。也许你们中的一个可以帮助我第 36 行,public static void printBoard(int[] meinBoard)
。
public class Main {
public static void main(String[] args) {
int turn=0;
String winner = null;
int[] board = new int[9];
for(int i = 0; i < board.length; i++){
board[i] = -1;
}
while(winner == null){
winner = "Player1";
}
printBoard(board);
}
/**
* # | # | #
* __________
* # | # | #
* ----------
* # | # | #
*/
public static void checkWinner(int[] board) {
int winner = -1;
if (board[0] == board[1] && board[0] == board[2] && board[0] != -1) {
winner = board[0];
} else if (board[3] == board[4] && board[3] == board[5] && board[0] != -1) {
winner = board[0];
}
public static void printBoard(int[] meinBoard) {
System.out.println(meinBoard[0] + " | " + meinBoard[1] + " | " + meinBoard[2]);
System.out.println("_________");
System.out.println(meinBoard[3] + " | " + meinBoard[4] + " | " + meinBoard[5]);
System.out.println("_________");
System.out.println(meinBoard[6] + " | " + meinBoard[7] + " | " + meinBoard[8]);
}
}
关闭方法 checkWinner:
public static void checkWinner(int[] board) {
int winner = -1;
if (board[0] == board[1] && board[0] == board[2] && board[0] != -1) {
winner = board[0];
} else if (board[3] == board[4] && board[3] == board[5] && board[0] != -1) {
winner = board[0];
}
} //<- add this
我建议你使用一个方便的IDE来标记你的非封闭方法,或者修复你的小代码问题
我是 Java 的新手,正在尝试学习它,但我的代码中总是出现此错误“java:表达式的非法开始”,我不知道为什么。也许你们中的一个可以帮助我第 36 行,public static void printBoard(int[] meinBoard)
。
public class Main {
public static void main(String[] args) {
int turn=0;
String winner = null;
int[] board = new int[9];
for(int i = 0; i < board.length; i++){
board[i] = -1;
}
while(winner == null){
winner = "Player1";
}
printBoard(board);
}
/**
* # | # | #
* __________
* # | # | #
* ----------
* # | # | #
*/
public static void checkWinner(int[] board) {
int winner = -1;
if (board[0] == board[1] && board[0] == board[2] && board[0] != -1) {
winner = board[0];
} else if (board[3] == board[4] && board[3] == board[5] && board[0] != -1) {
winner = board[0];
}
public static void printBoard(int[] meinBoard) {
System.out.println(meinBoard[0] + " | " + meinBoard[1] + " | " + meinBoard[2]);
System.out.println("_________");
System.out.println(meinBoard[3] + " | " + meinBoard[4] + " | " + meinBoard[5]);
System.out.println("_________");
System.out.println(meinBoard[6] + " | " + meinBoard[7] + " | " + meinBoard[8]);
}
}
关闭方法 checkWinner:
public static void checkWinner(int[] board) {
int winner = -1;
if (board[0] == board[1] && board[0] == board[2] && board[0] != -1) {
winner = board[0];
} else if (board[3] == board[4] && board[3] == board[5] && board[0] != -1) {
winner = board[0];
}
} //<- add this
我建议你使用一个方便的IDE来标记你的非封闭方法,或者修复你的小代码问题