Page 1 of 1

QUESTION 2 Consider the following implementation of hashCode(), in a class where str is a String: public int hashCode ()

Posted: Sat May 14, 2022 7:56 pm
by answerhappygod
Question 2 Consider The Following Implementation Of Hashcode In A Class Where Str Is A String Public Int Hashcode 1
Question 2 Consider The Following Implementation Of Hashcode In A Class Where Str Is A String Public Int Hashcode 1 (36.7 KiB) Viewed 35 times
QUESTION 2 Consider the following implementation of hashCode(), in a class where str is a String: public int hashCode () { int hash 0; int n str.length; for (int i=0; i<n; i++) { hash 31 * hash + str.charAt(i); } return hash; } If str="try": what does hashCode() return? [a] Note the following ASCII codes: t' is 116 'Tis 114 'Y' is 121