• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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)
 
Your mother was a hamster and your father was a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic