Java

Moderators: zibadian
Number of threads: 7832
Number of posts: 18231

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
This is a very simple programe of increment operator ..... Posted by karan8490 on 4 May 2011 at 7:15 AM
class a
{
public static void main(String[] a)
{
int i=1,j;
i=i++;
System.out.println("The value of i is "+i);
j=i++;
System.out.println("The value of j is "+j);
System.out.println("The value of i is "+i);
}}


//now i have problem that the value of i doesn't change when i increment in same referece variable value of i doesn't change but value of i change when i use other variable than i ?????
Report
Re: This is a very simple programe of increment operator ..... Posted by geraudk2000 on 4 May 2011 at 10:53 AM
OK You have to know the difference between ++i and i++;

when you use you use

++i : You increment the value of i then return .
i++ : returns the value of i and increment it after.


so use ++i instead i++;



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.