aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help: Oeperator  Associativity 2? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Help: Oeperator  Associativity 2?" Watch "Help: Oeperator  Associativity 2?" New topic
Author

Help: Oeperator Associativity 2?

Ruff Young
Ranch Hand

Joined: Sep 26, 2002
Posts: 513
The question below is at operators in Dan's Topic exam. The output is 1. The question looks so tricky. How do I group it? And could you give me some explanation of it in detail?
Each time execute part caculation, the variable 'i' is being changed? I think so.
Some my approch,
a compound assignment expression of the form E1 op= E2 can be rewritten as E1=(T)((E1)op(E2)) where T is the type of E1.
so i = i + (~i - -i * ++i + i-- % ++i * i++)
then i = 1 + (~i - -i * ++i + i-- % ++i * i++)
...
class F {
public static void main (String []s) {
int i = 1;
i += ~i - -i * ++i + i-- % ++i * i++;
System.out.print(i);
}
}
Thank you for your help?


SCJP2, SCWCD<br />IBM Certified WebSphere<br />IBM Certified Solution Developer for WSAD
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
With the following information you might be able to find out the solution:
Operator precedence
How does the ++ operator work?


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
This may help:My analysis of some expressions.
Your one is there too.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
The following class provides a sequence of simplified versions of the expression. Each print statement prints the same result.


I hope the above helps.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Ruff Young
Ranch Hand

Joined: Sep 26, 2002
Posts: 513
I really appreciate you explain kindly. I am planning to take the exam in next week.
 
Consider Paul's rocket mass heater.
 
subject: Help: Oeperator Associativity 2?