File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Increment Decrement Operators...Yet Again!!

 
Naveen Haimsley
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 158
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic