| Author |
Compound method explanation
|
cornel jew
Ranch Hand
Joined: Jul 13, 2002
Posts: 37
|
|
Hi I was doing one of Dan's mock exam on operators and came across the following code ,but could not really get the grip of the answers. Can someone please explain how to get the results with samples please. class C { static int m(int i) { System.out.print(i + ", "); return i; } public static void main(String s[]) { int i = 1; m(m(++i) - m(i++) + ~m(-i) * -m(~i)); } } The answers of 2,2 i understand but -3,-4, 8 i don't understand Thanks for any help
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
In case it wasn't clear to others reading this thread, the output of this program is "2, 2, -3, -4, 8". ------------------------ First - If you ask me, what you should really understand from this example, is that it's very bad practice to program like this. Code should be written to be easily read and understood. Big, complex statements with compound assignments are not easily read and understood. Second - cornel, what do you think the program should display and why?
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
 |
|
|
subject: Compound method explanation
|
|
|