Java Programming
April 26, 2007
Do u know basic of java,
then you can guess the answer of this simple question…
int j=1;
j+=j++;
System.out.println(j);
what is the output for the above statements
Check out the answer here
http://technoblizzard.blogspot.com/2007/04/core-java-programming.html
Powered by ScribeFire.
7 Comments Add your own
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed








1.
pegasus | April 27, 2007 at 2:01 pm
2….
u need to throw a much bigger problem.
2.
followtheshadow | April 27, 2007 at 2:19 pm
Bingo
Yes i know i should put some bigger problem,
just starting pa …
Actually i don’t know why the answer is 2..
can u explain….
3.
pegasus | April 27, 2007 at 2:57 pm
j+=j++;
print(j)
j++; instruction gets executed, but immediately afterwords the value of j is overwritten by j +=j;
instruction.
r u Comp Sci student?
4.
followtheshadow | April 27, 2007 at 5:42 pm
Yes i am …
5.
Virtuoso | April 30, 2007 at 2:40 pm
the answer is 2
j += j++.
This is same as j = j + j++.
The expression ” j + j++” is pushed into the stack.
The first element to be popped out is j which is equal to 1.
Next element is ‘+’.
The last element is j++, which means “first use j.. and then increment it”. So the present value of j is used, which is 1 again.
Adding the above values.. gives 2
hey di.. give a challenging problem
This is sooo simple
6.
Virtuoso | April 30, 2007 at 3:05 pm
hey no.. I mean the other way round….. sorry !
The first element is j++, which means “first use j.. and then increment it”. So the present value of j is used, which is 1.
Next element is ‘+’.
The last element to be popped out is j which was incremented to 2 at the first step.
Adding the above values.. 1 + 2 gives 3
So I guess the answer should be 3…
7.
followtheshadow | April 30, 2007 at 4:31 pm
@ Virtuoso
The answer is 2 ma…
Check it out.. It seems like simple/….