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.

Entry Filed under: life, study, technical. .

7 Comments Add your own

  • 1. pegasus  |  April 27, 2007 at 2:01 pm

    2….
    u need to throw a much bigger problem.

    Reply
  • 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…. :)

    Reply
  • 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?

    Reply
  • 4. followtheshadow  |  April 27, 2007 at 5:42 pm

    Yes i am …

    Reply
  • 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 :-)

    Reply
  • 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…

    Reply
  • 7. followtheshadow  |  April 30, 2007 at 4:31 pm

    @ Virtuoso

    The answer is 2 ma…
    Check it out.. It seems like simple/….

    Reply

Leave a Comment

Required

Required, hidden

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


Pages

Recent Comments

Oisin Horler on WORST VIRUS EVER — CNN…
zoey on Every Night In My Dreams- this…
zoey on Every Night In My Dreams- this…
amulya on Every Night In My Dreams- this…
Malaika on One of the best poem i have ev…

Top Posts

Recent Posts

a

Blogroll

 

April 2007
S M T W T F S
« Mar   May »
1234567
891011121314
15161718192021
22232425262728
2930  

Blog Stats

Java software

Meta

Flickr Photos

Po prostu - koń,

on the road again  ~  I'm back home ;-)

In a row for a new season

More Photos