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
12 Likes
Answer
x = (c >d) ? c : d;
Answered By
1 Like
Related Questions
What will be the output of the following code?
int fruit = 3; switch (fruit + 1) { case 1: System.out.println("Banana"); break ; case 2: System.out.println("Apple"); break ; case 3: System.out.println("Orange"); break ; default : System.out.println("Fruitless"); }
Predict the output of the following code snippet:
int a = 1; int b = 2; if (a == b) System.out.println ("Both values are equal"); else System.out.println ("Values are not equal");
if ((a > b) && (a > c)), then which of the following statements is true?
Consider the following code snippet:
int val = 2; switch (val) { case 1: System.out.println("Case 1"); break; case 2: System.out.println("Case 2"); break; default: System.out.println("No match found"); break; }
Which of the following statements is correct?