/** * q2: Write a public static method named q2 that takes a HashMap of type Str
ID: 3714549 • Letter: #
Question
/** * q2: Write a public static method named q2 that takes a HashMap of type String to Character * and returns an int. This method returns the *number of times* a most significant value * appears in the data where significant is defined as the char that comes last * alphabetically, ignoring case, from the values of the input (hint: The Character class has * static methods that convert chars to upper or lower case. In java, chars are represented * as ints so you can use < and > to compare them) */
Please use Java and PLEASE DO NOT USE "MAP.ENTRY".
Explanation / Answer
public static int q2(HashMap map) { char maxChar = 0; for(Character ch: map.values()) { if(Character.toLowerCase(ch) > maxChar) { maxChar = Character.toLowerCase(ch); } } int count = 0; for(Character ch: map.values()) { if(Character.toLowerCase(ch) == maxChar) { ++count; } } return count; }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.