The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

use ++i instead of i++

Posted by Wayne on December 28, 2000 at 9:27 PM

> Hi
> Can any one explain why the below program is givig out put 10 insted of 11
> public class incTest
> {
> public static void main(String [] arg)
> {
> int i = 10;
> i = i++;
> System.out.println(i);
> }

> }

> Thanx & Regards

> Ramesh

It is giving 10 because you have the statement "i++". Put the increment (++) in front of the "i" and it will first increment i, then assign it to i, giving you 11.





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us