0

Dear All,

I have a problem with Java Programming. I am writing a TatTicToe Program but I found a Error. It is a unexpected type for mark.equals("X")? currentPlayer=1: currentPlayer=0;

I don't know what happen. If you don't mind , I hope that All people will give some advises to this problem.

Thank you for your attention.

regards,
ming

The Detail of Execution Information :

init:
deps-jar:
Compiling 1 source file to C:\TicTacToe \build\classes
C:\TicTacToe \src\tictactoe \Server.java:242: unexpected type
required: variable
found : value
mark.equals("X")? currentPlayer=1: currentPlayer=0;
1 error
BUILD FAILED (total time: 7 seconds)

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by darkagn
0

You are using the value "X" in the .equals(Object) method which expects an Object as a parameter. It would be better if you declared your "X" as a constant String or char and compared the variable mark to that instead.

0

> You are using the value "X" in the .equals(Object) method which expects an Object as a
> parameter.

Huh? Firstly, the equals method is overridden in the String class. Secondly, if a method accepts an Object, you can pass any reference type to that method.

The problem here is that `conditional operator' is incorrectly used.

int currentPlayer = mark.equals("X") ? 1 : 0;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.