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
• Number of slices to send:
Optional 'thank-you' note:
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

Greenhorn
Posts: 1
• Number of slices to send:
Optional 'thank-you' note:
Could you please publish the full code, what the values of x1,x2 ... so on..

Regards
Suresh S

Ranch Hand
Posts: 332
• Number of slices to send:
Optional 'thank-you' note:
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