Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Beginning Java and the fly likes little problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "little problem" Watch "little problem" New topic

little problem

Rippon Jalali

Joined: Aug 25, 2006
Posts: 23
when i am trying to run below program.the output comes='0'.
BUt shouldn't it come '1'.

public class t {
public static void main(String argv[]) {

int i =0;


Stary Kapec
Ranch Hand

Joined: Dec 04, 2005
Posts: 81
int i = 0;
i=i++; // Here value of the expression i++ equals to 0, i is first incremented to 1, then assigned to the value of the expression, again to 0
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11689

Here is a more detailed explanation.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
subject: little problem