Write the output produced when the following method is passed each of the following maps: public static void mystery(Map m) { Set s = new TreeSet(); 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}
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}

Actually, given code is:
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);
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps









