Computer Applications
Read the if program segment given below:
if(a > b)
z = 25;
else
z = 35;
Which one of the following is the correct conversion of the if program segment to ternary?
- z = a > b ? 35 : 25;
- z = a > b ? 25 : 35;
- z = a > b : 35 ? 25;
- z = a > b : 25 ? 35;
Java Conditional Stmts
4 Likes
Answer
z = a > b ? 25 : 35;
Reason — The ternary operator follows the format condition ? value_if_true : value_if_false. In the given if-else statement, when a > b is true, z is assigned 25, otherwise it is assigned 35. Hence, the correct equivalent ternary expression is z = a > b ? 25 : 35;.
Answered By
2 Likes
Related Questions
Which of the following is NOT an access specifier?
- private
- protected
- package
- public
What is the output of the statement
Math.pow(36, 6/5);?- 36.0
- 1.0
- 73.71
- 6.0
The output of the statement:
System.out.println(Character.toUpperCase('b') + 2);is:- 66
- 100
- 68
- 98
Consider the following statements:
Computer desktop = new Computer(); Computer Mainframe = new Computer();Name the objects of the class given above:
- Desktop, Mainframe
- desktop, Mainframe
- Computer, Mainframe
- Computer, desktop