Hi,
You are "==" operator which checks either sides of references points to the same object .
That is checks the memory location not the contents . So use equals() function to check the contents( "X" in your case)of the String object .
Try to check the value("X") using looping statements rather than a cumbersome lengthy if statement
Hope this helps
parthiban
Junior Poster in Training
80 posts since Sep 2006
Reputation Points: 10
Solved Threads: 6
the crazy long line in the winner method
Start by splitting that line into fragments you can understand.
As the error says, you can't perform boolean operations on something that's not a boolean.
You're (it says, and I trust that it's right) comparing Strings with booleans there, which is not allowed.
In no small part that's no doubt because you wrote that entire crazy long line without giving thought to operator precedence rules, causing comparisons to happen that you are not aware of (and likely never intended).
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
public static boolean winner (String z[][])
{
if ( ( z[0][0]=="X" && z[0][1]=="X" && z[0][2]=="X" )
|| ( z[1][0]=="X" && z[1][1]=="X" && z[1][2]=="X" )
|| ( z[2][0]=="X" && z[2][1]=="X" && z[2][2]=="X" )
|| ( z[0][0]=="X" && z[1][0]=="X" && z[2][0]=="X" )
|| ( z[0][1]=="X" && z[1][1]=="X" && z[2][1]=="X" )
|| ( z[0][0]=="X" && z[1][1]=="X" && z[2][2]=="X" )
|| ( z[0][2]=="X" && z[1][1]=="X" && z[2][0]=="X" ) )
return true;
}
Ok the last term in that crazy long last line of yours didn't have anything to be compared to, "&&z[2][0])" which was wrong! I presumed it's like the others, and fixed it. Also I think that you would want each comparison to be separate, or else you would get the wrong answer a lot of the time. And finally, if you have a crazy long line like that, it might be better to sort it, like I've done above, makes it a lot easier to follow if you ask me.
mickinator
Junior Poster in Training
55 posts since Oct 2007
Reputation Points: 10
Solved Threads: 5