unable to make out this assignment in java

前端 未结 4 2122
长发绾君心
长发绾君心 2020-12-06 18:32

can anybody explain this why its happening

int i=0;
i=i++;
i=i++;
i=i++;
System.out.println(i);

it prints zero.

4条回答
  •  一个人的身影
    2020-12-06 19:17

    You meant to do this:

    int i = 0;
    i++;
    i++;
    i++;
    System.out.println(i);
    

    i++ actually does an assignment so if you add an = you just confuse things. These other fine responders can give you the nitty gritty, some details of it escape me. :)

提交回复
热议问题