aspose file tools*
The moose likes Beginning Java and the fly likes a doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "a doubt" Watch "a doubt" New topic
Author

a doubt

ranjan sarkar
Greenhorn

Joined: Jun 30, 2008
Posts: 7
class name
{public static void main(String[] args)
{int a=30;
a=a++;
System.out.println(a);
}
}

A:30

gives something unexpected output.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

http://faq.javaranch.com/java/PostIncrementOperatorAndAssignment


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Larry Frissell
Ranch Hand

Joined: May 16, 2008
Posts: 82
    
    2
That output is correct. See this recentthread
ranjan sarkar
Greenhorn

Joined: Jun 30, 2008
Posts: 7
but i need the perfect explanation.
please help me out
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18989
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11479
    
  16

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".


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ryan James
Greenhorn

Joined: Apr 18, 2007
Posts: 15
I'd imagine he think the output should be 31, having set 'a' at 30 and then assuming the a++ will add one.
 
Don't get me started about those stupid light bulbs.
 
subject: a doubt