Write the output produced when the following method is passed each of the follow
ID: 3571456 • Letter: W
Question
Write the output produced when the following method is passed each of the following maps:
public static void mystery(Map<String, String> m) {
Set<String> s = new TreeSet<String>();
for (String key : m.keySet()) {
if (!m.get(key).equals(key)) {
s.add(m.get(key));
} else {
s.remove(m.get(key));
}
}
System.out.println(s);
}
a. {sheep=wool, house=brick, cast=plaster, wool=wool}
b. {ball=blue, winkie=yellow, corn=yellow, grass=green, emerald=green}
Explanation / Answer
Question a. {sheep=wool, house=brick, cast=plaster, wool=wool}
Answer: [brick, plaster]
Question b. {ball=blue, winkie=yellow, corn=yellow, grass=green, emerald=green}
Answer: [blue, green, yellow]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.