aspose file tools
The moose likes Beginning Java and the fly likes a doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 1318

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


Saifuddin..
[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: 16695
    
  19

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: 9955
    
    6

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


Never ascribe to malice that which can be adequately explained by stupidity.
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a doubt
 
Similar Threads
Average age of Ranchers
how to limit number of characters in the text box
How old are you ?
Regarding salary.
Cool Names for Bands/Artists