Java Programming

April 26, 2007 at 7:14 pm 7 comments

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. Tags: .

And the Best Rapper award goes to……… God will show a way , where there seems to be no way..

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


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

Blog Stats

  • 225,814 hits

Java software

Flickr Photos

Morning Silence

Puffy

Emerald Damselfly โ™€

More Photos

%d bloggers like this: