Numeric Promotion in Conditional Expression
Conditional Statements in Java
In this article we will be discussing about Conditional Expression in Java.
A bool value’s output is used by the Conditional operator (?:) to determine which expression needs to be evaluated next.
No matter how much we try to improve our code, if-else conditions in programming often wind up being used repeatedly. Because of this, the conditional operator was created, which makes it simpler for us to write code because it has a specific syntax that it uses to evaluate the condition that is supplied to it.
The boolean value of one expression is used by the conditional operator?: to determine which of the other two expressions should be evaluated.
Syntax for Conditional Expression (?)
variable_name = Expression1 ? Expression2 : Expression3
Example without Conditional Operator:
Example with Conditional Operator:
Object obj = true ? new Integer(4) : new Float(2.0));
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others