Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Intersection and Union of Three or more Sets

1. ## 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

2. ## 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

3. ## Re: Intersection and Union of Three or more Sets

```
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);
return M;
}

public static  Set notB (Set setA, Set setB, Set setC) {
setA.removeAll(setB);
setC.removeAll(setB);
return setA;
}
public static  Set notA (Set setA, Set setB, Set setC) {
setB.removeAll(setA);
setC.removeAll(setA);
Set R = new TreeSet(setB);

return R;
}

public static void main(String[] args) {
TreeSet set1 = new TreeSet();
TreeSet set2 = new TreeSet();
TreeSet set3 = new TreeSet();

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

4. ## 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?

5. ## Re: Intersection and Union of Three or more Sets

I am sorry Jps now i have fixed it sorry for my bad english

6. ## 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.