| Author |
increment
|
sitaram irrinki
Ranch Hand
Joined: Feb 16, 2005
Posts: 158
|
|
class Test1 { public static void main(String[] args) { int i=0; System.out.println(i); i=i++; System.out.println(i); i=i++; System.out.println(i); i=i++; System.out.println(i); } } when i run this program then it is output all zero's why.
|
 |
Scheepers de Bruin
Ranch Hand
Joined: Jul 19, 2005
Posts: 99
|
|
The correct syntax for the ++ operator is: i++; That increments the variable i, no need for the i= bit.
|
We're doomed!!<br />Yay!!!<br />No that's bad Girr!!<br />Yay!!!
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
|
This is a very frequently asked question. For example, see this recent thread: http://www.coderanch.com/t/377970/java/java/Increment-Operator
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
|
OK, I finally put it into our FAQ: http://faq.javaranch.com/view?PostIncrementOperatorAndAssignment
|
 |
 |
|
|
subject: increment
|
|
|