Java Reference
In-Depth Information
12 {
13 Set<String> names = new
HashSet<String>();
14 Scanner in = new Scanner(System.in);
15
16 boolean done = false ;
17 while (!done)
18 {
19 System.out.print( ÐAdd name, Q when
done: Ñ );
20 String input = in.next();
21 if (input.equalsIgnoreCase( ÐQÑ ))
22 done = true ;
23 else
24 {
25 names.add(input);
26 print(names);
27 }
28 }
29
30 done = false ;
31 while (!done)
32 {
33 System.out.print( ÐRemove name, Q when
done: Ñ );
34 String input = in.next();
35 if (input.equalsIgnoreCase( ÐQÑ ))
36 done = true ;
37 else
38 {
39 names.remove(input);
40 print(names);
41 }
42 }
43 }
44
45 /**
46 Prints the contents of a set of strings.
47 @param s a set of strings
48 */
49 private static void print(Set<String> s)
50 {
Search WWH ::




Custom Search