• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ID:3 SCJP Question of the day : Thursday June 10 2010

 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will be the output of this code:




You know the rules, let's see your answers


Ref to rules... http://www.coderanch.com/t/498524/java-programmer-SCJP/certification/ID-SCJP-day-Wednesday-June

[HENRY: Added Reference. Change title id as requested]
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dude please do follow the Rules....If possible
Use ID3 instead of ID2

I have already posted ID2.......... i mean before you posted it !!!

You can just change the ID number to 3 in subject line !!!

Thanks for encouraging the concept !!!

Cheers!!!
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compilation Error :- I think ^(XOR) can be applied to integers only ~~!!!
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about the ID, when I started to post, your thread wasn't up yet. I will try to change it

... and your answer is correct, while the explanation isn't . The '^' XOR can be applied to booleans.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please leave the name out of the subject - it's long enough as it is. What's more, the name is visible wherever the topic title is visible, so it's redundant to begin with.
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf is right. We could shorten the titles to just "ID# SCJP QOTD" since all othed info is visible wher you select the thread
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Please leave the name out of the subject - it's long enough as it is. What's more, the name is visible wherever the topic title is visible, so it's redundant to begin with.


Okay i agree, we would leave the name of an author from now onwards , but please do keep the date , inspite of being redundant, it looks attractive !!!

 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If XOR can be applied to booleans
then

Compilation error is on line 12

as (short+short) is solved to (int)
and then int cannot be applied to short again without the explicit cast.

So we could do the following :-

 
Peter Taucher
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code doesn't compile. But if you'd cast the result of the addition / subtraction to short it would be '100'...
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sahil and Peter got it right! I'll try to make it more of a challenge the next time
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Sahil because ... the auto conversion mechanism of java converts short to int when compiling so we need to re cast the same to short .

@sahil ... XOR can be applied to boolean values as well
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Lalit , i remember it now !!!

 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Sahil --> your welcome bro
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic