Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Fubarable

Thread: What is this code equivalent to?

  1. #1
    juxta is offline Member
    Join Date
    Nov 2011
    Posts
    30
    Rep Power
    0

    Default What is this code equivalent to?

    Hi guys, I have encountered this code:

    Java Code:
    int leftTreeHeight ;
    leftTreeHeight = (leftSide == null) ? 0 : leftSide.height();
    What is this code equivalent to and look like? I have researched and found nothing about it.

    Thanks.
    Last edited by juxta; 01-04-2013 at 12:57 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: What is this code equivalent to?

    You are seeing the ternary operator which functions somewhat like:

    Java Code:
    if (leftSide == null) {
      leftTreeHeight = 0;
    } else {
      leftTreeHeight = leftSide.height();
    }
    juxta likes this.

  3. #3
    nonybrighto is offline Member
    Join Date
    Oct 2012
    Location
    ph
    Posts
    43
    Rep Power
    0

    Default Re: What is this code equivalent to?

    i'm sure the code is not complete but the part with ? And : ..... Something like
    x = (y <10)? 20 : 50
    if y is less than 10, x = 20 else, x=50....i dont know if that is what you are looking for
    joy wouldnt feel so gud if it wasnt for pain

  4. #4
    juxta is offline Member
    Join Date
    Nov 2011
    Posts
    30
    Rep Power
    0

    Default Re: What is this code equivalent to?

    Quote Originally Posted by juxta View Post
    Hi guys, I have encountered this code:

    Java Code:
    int leftTreeHeight ;
    leftTreeHeight = (leftSide == null) ? 0 : leftSide.height();
    What is this code equivalent to and look like? I have researched and found nothing about it.

    Thanks.
    Thanks a lot :)

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: What is this code equivalent to?

    Quote Originally Posted by nonybrighto View Post
    i'm sure the code is not complete ...
    The original code is in fact complete.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: What is this code equivalent to?

    Quote Originally Posted by juxta View Post
    Thanks a lot :)
    You're welcome.

Similar Threads

  1. What is equivalent for loop?
    By diamonddragon in forum New To Java
    Replies: 5
    Last Post: 01-15-2012, 10:16 AM
  2. HQL equivalent to this Sql Query
    By shomid in forum Advanced Java
    Replies: 0
    Last Post: 10-27-2011, 09:43 AM
  3. Replies: 1
    Last Post: 07-14-2011, 02:14 AM
  4. VB Net FIX equivalent?
    By bullstreetboy in forum New To Java
    Replies: 3
    Last Post: 04-06-2009, 06:31 PM
  5. Replies: 1
    Last Post: 11-21-2007, 01:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •