? in java


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: ? in java

  1. #1
    Join Date
    Apr 2007
    Posts
    2

    Exclamation ? 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

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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?

  3. #3
    Join Date
    Apr 2007
    Posts
    2
    Quote 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

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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

  1. Java book
    By Lou in forum Java
    Replies: 9
    Last Post: 09-19-2007, 06:58 AM
  2. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 07:46 AM
  3. DevX does seem one sideded
    By Rob Abbe in forum Talk to the Editors
    Replies: 44
    Last Post: 01-13-2003, 03:57 PM
  4. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 05: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center