? in java
just a simple question thats wrecking my head, what does a ? mean in java
static int opponent(int turn)
return turn==BLACK ? WHITE : BLACK;
BLACK = 1
WHITE = 2
turn = either 1 or 2
what would this mean, mainly the ? and :
this is a single statement "if-then-else" construction. One of the few "three part" - ternary - operations in Java. The statement is read as "if the value of turn currently equals BLACK then it is now going to be WHITE, else (if turn isn't currently BLACK) then it will be black's turn".
Have you thought about using Enumerations for your BLACK, WHITE ness?
not too sure what enumerations are, sure i probably do but dont know name, ur right it is a game of checkers and that just helped my out a lot, thanks
Originally Posted by nspils
Don't spend time on Enumerations in the middle of your project, but it is something you should look at to expand your abilities. This is a way to create an integral datatype with a label other than a digit. Much more readable for people, in the place of "magic numbers" like 1 or 2.
Last Post: 09-19-2007, 05:58 AM
Last Post: 05-13-2005, 06:46 AM
By Rob Abbe in forum Talk to the Editors
Last Post: 01-13-2003, 02:57 PM
By JJ in forum Enterprise
Last Post: 07-06-2000, 04:50 AM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center