Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

question

Thread view: 
parwal.sandeep@gmail.com - 17 Feb 2006 05:07 GMT
hello grp !!!
  i've one question plz excuse if it is silly to ask !!

public static void main( String[] args )
{
    int i=10;
     i = i++;
     SOP (i);
}

why it is printing  10 instead of 11 ??
pit.grinja@gmx.de - 17 Feb 2006 08:33 GMT
Hi,
> public static void main( String[] args )
> {
[quoted text clipped - 4 lines]
>
> why it is printing  10 instead of 11 ??
"i++" means: first return old value, then increment i. So first you
"reassign" i to the old value of i, and then increment i or more
probably, a home- and nameless primitive integer variable that used to
be called "i" before you used that name for something else.
To do what you want, namely increment first, then return the new,
incremented value, you have to write:
public static void main( String[] args )
{
     int i=10;
      i = ++i;
      SOP (i);
}
That should work.
Regards, Piet


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.