? 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, 06:58 AM
Last Post: 05-13-2005, 07:46 AM
By Rob Abbe in forum Talk to the Editors
Last Post: 01-13-2003, 03:57 PM
By JJ in forum Enterprise
Last Post: 07-06-2000, 05:50 AM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL