• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

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)
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic