-
? 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 :
thankin you
-
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".
Chess? Checkers?
Have you thought about using Enumerations for your BLACK, WHITE ness?
-
 Originally Posted by nspils
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".
Chess? Checkers?
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
-
You're welcome.
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.
Similar Threads
-
Replies: 9
Last Post: 09-19-2007, 05:58 AM
-
Replies: 1
Last Post: 05-13-2005, 06:46 AM
-
By Rob Abbe in forum Talk to the Editors
Replies: 44
Last Post: 01-13-2003, 02:57 PM
-
By JJ in forum Enterprise
Replies: 1
Last Post: 07-06-2000, 04:50 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks