aspose file tools*
The moose likes Beginning Java and the fly likes Difference in output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference in output" Watch "Difference in output" New topic
Author

Difference in output

Phillipe Rodrigues
Ranch Hand

Joined: Oct 30, 2007
Posts: 165
Why i am getting different outputs for the below programs?

Program1:


Output:
---------- RUN ----------
5

Output completed (0 sec consumed) - Normal Termination

----------------------------------------------------------------------
Program 2:


Output:
---------- RUN ----------
6

Output completed (0 sec consumed) - Normal Termination


Thanks,
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

You're using the postfix increment operator. That returns the old value before incrementing. The prefix increment operator (++a) will return the new increased value.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Difference in output
 
Similar Threads
constructor
about contructor
Compile time erroe in the code.
Arithmetic Compound Assignment Operators..
Math.round( -.5)?