top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

What is ternary operator in Java? can you Give me an example this operator ?

+2 votes
51 views
What is ternary operator in Java? can you Give me an example this operator ?
posted May 31, 2017 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Ternary operator lets you assign a value to a variable based on a boolean expression if true then one value if false then another value. In simple language, a ternary operator is a conditional operator, which can be used as an alternative to the Java if/then/else syntax, but it goes beyond that, and can even be used on the right-hand side of Java statements.It is mainly used when the variables are initialized based on the conditions.

Example

minVal = (a < b) ? a : b;
absValue = (a < 0) ? -a : a;
answer May 31, 2017 by Salil Agrawal
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...