# Intersection and Union of Three or more Sets

• August 18th, 2013, 10:26 PM
robertm08
Intersection and Union of Three or more Sets
I need help i have to write a program to verify if a set is a subset of the other that A intersect B intersect C = A' union B' union C'
I am new to this forum Thanks in advance
• August 18th, 2013, 10:54 PM
jps
Re: Intersection and Union of Three or more Sets
Welcome robertm08
What is it you need help with?
Sounds like the description is of several problems, choose one to work with first, and let us know what you get stuck on
• August 18th, 2013, 11:14 PM
robertm08
Re: Intersection and Union of Three or more Sets
Code Java:

```  package SetTheory;   import java.util.HashSet; import java.util.Set; import java.util.TreeSet;     public class test {   /** * @param args */   public static Set intersection(Set setA, Set setB, Set setC) { Set S = new TreeSet(setA); S.retainAll(setB); S.retainAll(setC); return S; }   public static Set union(Set setA, Set setB, Set setC) { Set M = new TreeSet(setA); M.addAll(setB); M.addAll(setC); return M; }   public static Set notB (Set setA, Set setB, Set setC) { setA.removeAll(setB); setC.removeAll(setB); setA.addAll(setC); return setA; } public static Set notA (Set setA, Set setB, Set setC) { setB.removeAll(setA); setC.removeAll(setA); Set R = new TreeSet(setB); R.addAll(setC);   return R; }   public static void main(String[] args) { TreeSet set1 = new TreeSet(); TreeSet set2 = new TreeSet(); TreeSet set3 = new TreeSet();     set1.add('a'); set1.add('d'); set1.add('e'); set1.add('g');   set2.add('b'); set2.add('d'); set2.add('f'); set2.add('g');   set3.add('c'); set3.add('f'); set3.add('e'); set3.add('g');   System.out.println("Union:" + union(set1, set2, set3)); System.out.println("Intersection:" + intersection(set1, set2, set3)); System.out.println("B' = " + notB(set1, set2, set3)); System.out.println("A' = " + notA(set1, set2, set3)); }   }```
output
Union:[a, b, c, d, e, f, g]
Intersection:[g]
B' = [a, c, e]
A' = [b, d, f, g]

the first difference output from B' is correct because B' = (A-B)+(C-B) = a,c,e
i am confused because of the output of A' = (B-A)+(C-A) i need to make the output to be b,f,c
• August 19th, 2013, 12:38 AM
jps
Re: Intersection and Union of Three or more Sets
Please use code tags when posting code, assistance can be found on the Announcements Page.

Please do note that we do not provide solutions, we provide suggestions, but I do not understand what it is you need help with. What are you stuck on?
• August 19th, 2013, 01:06 AM
robertm08
Re: Intersection and Union of Three or more Sets
I am sorry Jps now i have fixed it sorry for my bad english
• August 19th, 2013, 10:18 AM
jps
Re: Intersection and Union of Three or more Sets
I'm sorry too... I still do not see your question or a description of the problem you are stuck on.