• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a doubt

 
ranjan sarkar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class name
{public static void main(String[] args)
{int a=30;
a=a++;
System.out.println(a);
}
}

A:30

gives something unexpected output.
 
Larry Frissell
Ranch Hand
Posts: 82
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That output is correct. See this recentthread
 
ranjan sarkar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i need the perfect explanation.
please help me out
 
Henry Wong
author
Marshal
Pie
Posts: 21221
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by RANJAN SARKAR:
but i need the perfect explanation.
please help me out


What is not "perfect" about the explanation? The links explains it to the full detail.

Henry
 
fred rosenberger
lowercase baba
Bartender
Posts: 12149
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it would also help, generally speaking, if you would explain what YOU think the output should be. Many people here will look at that and think "30 is exactly what I'd expect the output to be."

at that point, they then have to try and guess what you think the output should be, which can lead to all kinds of trouble.

if you say "Well, i think THIS should be the output, and here's WHY", it's much easier for someone to reply with "well, you make a false assumption HERE, and your logic is wrong THERE".
 
Ryan James
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd imagine he think the output should be 31, having set 'a' at 30 and then assuming the a++ will add one.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic