Monday, October 14, 2013

Random Snippets in Core Java

                       
 1. The ?: operator in java

    if (a>b)
          val=a;
    else
          val=b;
The above can be written as val = (a>b) ? a: b
Note: the types you are comparing and the types you're assigning must be same e.g if a and b are int (a>b) then val must be int

No comments:

Post a Comment