Computer Applications
Consider the following code snippet
if (c > d)
x = c;
else
x = d;
Choose the correct option if the code mentioned above is rewritten using the ternary operator.
- x = (c > d) ? c : d;
- x = (c > d) ? d : c;
- x = (c > d) ? c : c;
- x = (c > d) ? d : d;
Java Conditional Stmts
26 Likes
Answer
x = (c > d) ? c : d;
Reason — Correct syntax of ternary operator is:
variable = (test expression) ? exp 1 : exp 2
If the test expression is true, exp 1 is assigned to variable, else exp 2 is assigned to the variable.
Answered By
10 Likes
Related Questions
Which clause is optional in the switch statement?
- default
- case
- switch
- None of these
Errors occur in a program when :
- Syntax of the programming language is not followed
- the program does not run properly or does not execute at all
- The program produces an incorrect result
- All of the above
Object that share the same attributes and behaviour are grouped together into a/an
- interface
- instance
- alias
- class
The statement
(1 > 0) || (1 < 0)evaluates to- 0
- 1
- false
- true