Tuesday 28 June 2016

conditional operator (? :) in java

We have covered conditional operator ? : in previous chapter which can be used to replace if...else statements. It has the following general form:
Exp1 ? Exp2 : Exp3;
Where Exp1, Exp2, and Exp3 are expressions. Notice the use and placement of the colon.
To determine the value of whole expression, initially exp1 is evaluated
  • If the value of exp1 is true, then the value of Exp2 will be the value of the whole expression.
  • If the value of exp1 is false, then Exp3 is evaluated and its value becomes the value of the entire expression.

No comments:

Post a Comment