This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A question about Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A question about "- -"" Watch "A question about "- -"" New topic
Author

A question about "- -"

Kelvin Mak
Ranch Hand

Joined: Oct 04, 2002
Posts: 51

output is: 1
0
why there is no affect value b at line 1?


SCJP1.4
Keen Chen
Ranch Hand

Joined: Nov 12, 2002
Posts: 47
in line 1, - -b equals "negative and negative b",so ,it's b


SCJP 1.4 100% @ Peking, China <br />~~~~~~~~~~~~~~~~~~~~~<br />但使龙城飞将在, 不教胡马度阴山!
Arpana Rai
Ranch Hand

Joined: Nov 12, 2002
Posts: 93
Kelvin,
this needs a little undetstanding of operators.
In the code at line 1 (- -b) will execute as
(-(-b)), so there is no change in the orginal value of b.but at verry next line (--b) 1st decrement the value of b and then will print it.
regds
Arpana


SCJP1.4(91%)
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
with the space, "- -b" means you are negating b twice.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Arpana Rai
Ranch Hand

Joined: Nov 12, 2002
Posts: 93
Yes,Ron..you got the point.
regds
Arpana
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Just my .2$
From JLS 3.2 Lexical Translations

The longest possible translation is used at each step, even if the result does not ultimately make a correct program while another lexical translation would. Thus the input characters a--b are tokenized (�3.5) as a, --, b, which is not part of any grammatically correct program, even though the tokenization a, -, -, b could be part of a grammatically correct program.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question about "- -"
 
Similar Threads
threads are started when JVM starts
Covariant returns
followed by an exception
static block and empty block inside any class.
doubt in instanceof operator..