Results 1 to 2 of 2
  1. #1
    thegamer123 is offline Member
    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0

    Default the meaning of "?"

    Hello,

    right now I have some trouble to understand this line:

    String zeichen = r < 10 ? "" + r : "" + (char) (r + 55);

    r is an int.

    I dont get the meaning of the "?" and ":"

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,098
    Rep Power
    4

    Default Re: the meaning of "?"

    To summarize, it's a shortcut for an if-then-else: if (condition) ? <then part> : <else part>;

    Your example can also be written as:
    Java Code:
    String zeichen = null;
    if ( r < 10) {
      zeichen = "" + r;
    }
    else {
       zeichen = "" + (char) (r + 55);
    }
    The official name is a ternary operator.
    Last edited by SurfMan; 02-18-2013 at 01:05 PM. Reason: Typo

Similar Threads

  1. Replies: 0
    Last Post: 12-07-2012, 09:29 AM
  2. Meaning of "multiply" in the following code?
    By Pover9000X in forum New To Java
    Replies: 1
    Last Post: 04-09-2012, 04:17 AM
  3. Meaning of "String..."
    By kracer in forum New To Java
    Replies: 1
    Last Post: 05-29-2010, 01:10 AM
  4. what is the meaning of "@" in java
    By itaipee in forum New To Java
    Replies: 3
    Last Post: 08-03-2009, 12:17 PM
  5. Replies: 1
    Last Post: 10-20-2008, 08:35 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
  •