Program basics

If a=54,b=34,c=43 then find the output of this JAVA statement.

int d;

d=a>b?(a>c?a:c):(b>c?b:c);

System.out.print(d);


The answer is 54.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Arulx Z
Aug 29, 2015

Here is a pseudo code of ternary opertor

1
VARIABLE = CONDITION ? VALUE 1 : VALUE 2

If the condition is true, then VALUE 1 is assigned to VARIABLE else if the condition is false, VALUE 2 is assigned to VARIABLE .

Note: Python implements ternary operator differently but the concept is same.

Evaluating the given expression using the above logic, we find the answer as 54.

Moderator note:

Great! Thanks for explaining that!

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...