Eric Geerts Eric Geerts - 5 months ago 9
Java Question

Begginer Help: What is wrong with this method?

Im creating a tic tac toe game and this is the way I am checking for the win, but i get this list of errors about this section of code.


/tmp/java_hoEysf/TicTacToe.java:195: error: not a statement Public
void Checkforwin(); ^ /tmp/java_hoEysf/TicTacToe.java:195: error:
';' expected Public void Checkforwin();
^ /tmp/java_hoEysf/TicTacToe.java:195: error: illegal start of expression Public void Checkforwin();


Can anyone help me out an tell me what I'm doing wrong?
(Code is not complete im just wondering why the method wont work

Code:

public void checkForWin() {
if (board [0][0] + board[0][1] + board[0][2] == 15) {
btnA3.setText("Ax");
win = 1;
}

if (board [0][0] + board[0][1] + board[0][2] == 30) {
btnA3.setText("Ao");
win = 2;
}

if (board[1][0] + board[1][1] + board[1][2] == 15) {
btnA3.setText("Ax");
win = 1;
}

if (board[1][0] + board[1][1] + board[1][2] == 30) {
btnA3.setText("Ao");
win = 2;
}

if (board[2][0] + board[2][1] + board[2][2] == 15) {
btnA3.setText("Ax");
win = 1;
}

if (board[2][0] + board[2][1] + board[2][2] == 30) {
btnA3.setText("Ao");
win = 2;
}

if (board[0][0] + board[1][0] + board[2][0] == 15) {
btnA3.setText("Ax");
win = 1;
}

if (board[0][0] + board[1][0] + board[2][0] == 30) {
btnA3.setText("Ao");
win = 2;
}
}

Answer

In Java the right keyword is public not Public, indeed it is case sensitive.

You can find the list of all the existing keywords in Java and their meaning here.

Comments