This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I am wondering ...

 
Jagat Jyoti Das
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to compile and run this piece of code.
The value of i remains the same even after I increment it . Please run the code to see the same.
public class test{

public void test1(){
int i=1;
System.out.println(i);
i=i++;
System.out.println(i);
}
public static void main(String[] args)
{
test k =new test();
k.test1();
System.out.println("Do you see something ??");
}
}
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This behavior is perfectly correct and has to do with the way the ++ operator works.
Please see the following discussion about the ++ operator:
http://www.coderanch.com/t/190825/java-programmer-SCJP/certification/Array
 
Prasad Kuppa
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Valentin. You have directed to very good thread. Where can I find list of these very good archived threads?
Prasad
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try here:
http://www.javaranch.com/maha/Discussions/discussions.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic