« Look Ma! Null Reference But No NullPointerException? | Main

05/05/2012

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00e5501e33db88340163053e9a23970d

Listed below are links to weblogs that reference What Will This Java Code Print ?:

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Sai Matam

Keith,

Since it is a simple program - all it takes is to save the given code into a .java file, compile and run :-) I thought it would be fun and instructive to actually run the code and experiment more.

--Sai Matam.

Keith

The answer is actually #3. You should have done a quick test before answering. And Java supports Unicode, not ASCII. It so happens J = 74 in both standards.

Sai Matam

Dan,

You are right. There is a difference in using "J" (a String) and 'J' ( a char). When I first encountered this, I was very surprised. I thought I would share with everyone.

regards,
Sai Matam

Dan

You also get a different answer when using "J" versus 'J'.

However, in php you get the same answer regardless of "J" or 'J'.

Sandeep

Ans should be 4th option

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment