File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes evaluation of expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "evaluation of expression" Watch "evaluation of expression" New topic

evaluation of expression

Naresh Gunda
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
How to evaluate the following expression

Can any one of u tell me, which operators are left associative and which operators are right associative?

Thanx in advance
Abhishek Sharma
Ranch Hand

Joined: Jan 09, 2006
Posts: 68
Hi there,
After the execution of this expression b1 will have value
FALSE as this expression consists of subexpressions, and therefore
first of all subexpressions will be evaluated
in given question
boolean b1 = false?false:true?false:true?false:true;
it will break to
boolean b1 = (false?false true?false true?false:true)));
and result is accordingly...........
Prashanth Raghavan

Joined: Dec 10, 2004
Posts: 6
It ultimately boils down from the rightmost to the left. The subexpressions get executed and the results assigned and this continues in a chain from right to left.

Prashanth R<br />Chennai
Narender Kumar

Joined: Jan 03, 2006
Posts: 11
I think this is one of those
"think-like-a-compiler" kinda question.

lets see how we can evaluate this expression.
move from left to right as per associativity rules.

step 1: input--> false?false:true?false:true?false:true;
output--> false?false true?false:true?false:true);

step 2: input--> false?false true?false:true?false:true);
output--> false?false true?false true?false:true));

step 3: input--> false?false true?false true?false:true));
output--> false?false true?false true?false true)));

brackets shud clear your doubt a little bit....
does it??

"Rock Steady"
Narender Kumar

Joined: Jan 03, 2006
Posts: 11
oh nooooooooo....
i didnt not put soooo many sad emoticons in my message.

Narender Kumar

Joined: Jan 03, 2006
Posts: 11
i am not gonna give up this easy.

step 1: input--> false?false:true?false:true?false:true;
output--> false?false: (true?false:true?false:true);

step 2: input--> false?false: (true?false:true?false:true);
output--> false?false: (true?false: (true?false:true));

step 3: input--> false?false: (true?false: (true?false:true));
output--> false?false: (true?false: (true?false true)));
I agree. Here's the link:
subject: evaluation of expression
jQuery in Action, 3rd edition