File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes increment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "increment " Watch "increment " New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: increment
 
Similar Threads
auto boxing additions
how to create this in java
Enhanced For Loop
Strange IF condition
Set all ComponentOrientation to rtl