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)

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.

> 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;

Oops, of course you are correct SOS. Sorry for the blunder, wasn't thinking! :$

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.