(--x) Vs (- - x)

int x;x = (x=1) + (x=7)* (- - x); System.out.println( x );why does the output of the above statements differ from the one given below..int x;x = (x=1) + (x=7)* (--x); System.out.println( x );Thanks in advance....
[268 byte] By [Sundar.nagarathinama] at [2007-11-26 16:31:10]
# 1
> x = (x=1) + (x=7)* (- - x); > x = (x=1) + (x=7)* (--x); '--' (no spaces) is a unary pre-decrement operator; '- -' (a space in between)are two minus signs.kind regards,Jos
JosAHa at 2007-7-8 22:55:41 > top of Java-index,Java Essentials,New To Java...
# 2
I think 2007 is better then 2006.In 2006 everybody ask "why is this code i = i++ <do something>?"In 2007 expression is greater and stranger with ( x = C ) elements and --x instead of i++.Readers of this forum became smarter. Very good :)
Michael.Nazarov@sun.coma at 2007-7-8 22:55:41 > top of Java-index,Java Essentials,New To Java...
# 3
Thanks for your appreciation
Sundar.nagarathinama at 2007-7-8 22:55:41 > top of Java-index,Java Essentials,New To Java...
# 4
> Readers of this forum became smarter.Let's hope the same for the writers to this forum. ;)
CeciNEstPasUnProgrammeura at 2007-7-8 22:55:41 > top of Java-index,Java Essentials,New To Java...
# 5
> Let's hope the same for the writers to this forum. ;)I've been waiting for this note :)
Michael.Nazarov@sun.coma at 2007-7-8 22:55:41 > top of Java-index,Java Essentials,New To Java...
# 6
is there any difference between those 2 statements --x is going to decrement the value of x by 1 before any processing..also - - x is going to subtract...
Sundar.nagarathinama at 2007-7-8 22:55:41 > top of Java-index,Java Essentials,New To Java...
# 7
i am not able to draw a clear picture of what u said......can you please explain it breifly.....I have interpreted as follows x = 1 + 7 * (--7)= 1 + 7 * 6= 43and for subtraction x = 1 + 7 * ( - - 7)= 1 + 7 * ?
Sundar.nagarathinama at 2007-7-8 22:55:41 > top of Java-index,Java Essentials,New To Java...
# 8
> --7I'm sorry. Somebody, please, delete my first post. Or last statement within at least...
Michael.Nazarov@sun.coma at 2007-7-8 22:55:41 > top of Java-index,Java Essentials,New To Java...
# 9
Perhaps if you placed brackets around the expression it may help; so - -7 could become (-(-7)). What the expression is actualy doing is reversing the sign of negative seven; - -7 is actually 7. Therefore, your eaxmple - x = 1 + 7 * ( - - 7) - will return the value 56 - (8 * 7).
Tillermana at 2007-7-8 22:55:41 > top of Java-index,Java Essentials,New To Java...
# 10
I got it .... Thanks a lot
Sundar.nagarathinama at 2007-7-8 22:55:41 > top of Java-index,Java Essentials,New To Java...
# 11

> I think 2007 is better then 2006.

> In 2006 everybody ask "why is this code i = i++ <do

> something>?"

> In 2007 expression is greater and stranger with ( x =

> C ) elements and --x instead of i++.

> Readers of this forum became smarter. Very good :)

You're a bit early to make that assessment, what with the year being less than one month old. The Great Influx of Zero Year schoolkids won't start for 6 months...

jwentinga at 2007-7-8 22:55:41 > top of Java-index,Java Essentials,New To Java...