File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Increment Decrement Operators...Yet Again!! 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 "Increment Decrement Operators...Yet Again!!" Watch "Increment Decrement Operators...Yet Again!!" New topic
Author

Increment Decrement Operators...Yet Again!!

Naveen Haimsley
Greenhorn

Joined: Dec 16, 2012
Posts: 3
I know this has been discussed umpteen times before.
But can anyone come up with an easier explanation.....preferably in layman terms to make a new bee happy!?

What and how?

int i=0;
i=i++;
System.out.println(i);
James X Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 158
Hi Naveen Haimsley,

int x=1;
int i=x++;


As we have used post increment first the value of x is stored in i and the value of x is incremented. so the values of x and i are 2 ,1 respectively.

int x=1;
int i=++x;

As we have used pre increment first the value of x is incremented and the that incremetned value is stored in i. so the values of x and i are 2 ,2 respectively.

Regards,
James
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14104
    
  16

See our frequently asked questions page: Post increment operator and assignment


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Increment Decrement Operators...Yet Again!!