Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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]