• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

master exam doubt

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int x=0;
if(x1.hashcode()!=x2.hashcode())x=x+1;
if(x3.equals(x4)==false)x=x+10;

if(x5.equals(x6)==true)x=x+100;

if(x7.hashcode()==x8.hashcode())x=x+1000;


If o/p is 1111
which is always true
x5.hashcode()==x6.hashcode()
x3.hashcode()!=x4.hashcode()
x1.equals(x2)==true
x7.equals(x8)==true


I thinks answer should be x5.hashcode()==x6.hashcode()
but the answer was given x1.equals(x2)==true
Is answer given wrong?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please publish the full code, what the values of x1,x2 ... so on..

Regards
Suresh S
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are right.



if x1.equals(x2)==true
then they should give same hashcode, but then the output can not be 1111 (you would miss 1 at the end)
 
This guy is skipping without a rope. At least, that's what this tiny ad said:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic