jQuery in Action, 2nd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes variables Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "variables" Watch "variables" New topic
Author

variables

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hai,
i want why the output is different in java for the below code
---
int a=2;
a=a++;
System.out.println(a);
---
the output is 2
why
&how the code is executed(i want some algor)
thank u
srinivasan.e

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
It's because the expression
a++
is evaluated after the assignment.
a is assigned a and then a is increased by 1.
Instead use only the statement a++ or a=++a instead.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: variables
 
Similar Threads
MarcusGreenExam1 #1
variables
switch & case problem
Doubt in formatting
inner class problem