It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes x+ or x- (single shortcut increment operator) 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 "x+ or x- (single shortcut increment operator)" Watch "x+ or x- (single shortcut increment operator)" New topic

x+ or x- (single shortcut increment operator)

Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
This is driving me crazy. My compiler doesn't like it if you type something like x+ or -y or var+ or whatever if you're trying to increment. It only accepts stuff like x-- or ++y, and that's what I always would have expected, but this MasterExam software that came with my SCJP2 book CD likes to throw it into questions a lot, and I can believe that the real exam might. However, what really tripped me up is that the practice software seems to think that it is a bona fide statement! What is going on here? This is like the Twilight Zone or something, and I'm taking the exam on Monday, so I'm freaking out about it. The software does seem a little messed up, especially since my copy makes it hard or impossible to go back and view questions in the practice exam after time has already expired. Thus, I can't exactly verify that I wasn't going nuts while taking the exam. (I specifically recall choosing an answer, checking my progress, and then trying other answers until it told me I'd chosen the correct answer, and the correct answer included one of those nasty statements with a single increment operator). Maybe I'm just loco, and should commit myself...or dance naked on the beach in winter.
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

make sure you let us know what beach and where
When in doubt -- check the JLS. There are 6 unary operators: +, -, ++, --, ~, !.
Those first two: + and - are not increment operators -- they are positive / negative -- used to change the sign of the number its in front of.
++ and -- are the increment operators we all know and love.
Not having seen the question -- I'd say you're right in doubting what you saw. Mock exams have known to be wrong, the real exam is tricky -- but it doesn't have any errors in it.
Good luck tomorrow! Get a good night's sleep!
I agree. Here's the link:
subject: x+ or x- (single shortcut increment operator)
jQuery in Action, 3rd edition