Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

simple increment doubt.please help  RSS feed

 
silent java
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class test{
public static void main(String[] args)
{
int i=0;
i=i++;
System.out.println(i);
}
}


the o/p is zero,please someone tell me y.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"silent java",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with display names get deleted, often without warning

Also, I can't see which other person you are refering to

thanks,
Dave
 
Biswajit Paria
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class test{
public static void main(String[] args)
{
int i=0;
i=i++;
System.out.println(i);
}
}


it is happening because you are asigning value of i before it gets incremented.

Regards,
Biswajit.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can also search this forum, as this question is regularly asked and answered.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!