-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
55 lines (34 loc) · 1.65 KB
/
Copy pathMain.java
File metadata and controls
55 lines (34 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
public class Main {
public static void main(String[] args) {
Conjunto<Integer> c1 = new ConjuntoVazio<>();
// c1 = {1, 2, 3, 4, 5}
for(int i = 0; i <= 5; i++) {
c1 = c1.adicionarElemento(i);
}
// c2 = {1, 3, 5, 7, 9}
Conjunto<Integer> c2 = new ConjuntoVazio<>();
for(int i = 1; i <= 10; i = i + 2) {
c2 = c2.adicionarElemento(i);
}
System.out.println(c1.contemElemento(2)? "2 ∈ c1" :"2 ∉ c1");
System.out.println(c1.contemElemento(7)? "7 ∈ c1" :"7 ∉ c1");
System.out.println(c2.contemElemento(7)? "7 ∈ c2" :"7 ∉ c2");
System.out.println(c2.contemElemento(8)? "8 ∈ c2" :"8 ∉ c2");
// c3 = c1 U c2 = {1, 2, 3, 4, 5, 7, 9}
Conjunto<Integer> c3 = c1.uniao(c2);
System.out.println(c3.contemElemento(5)? "5 ∈ c3" :"5 ∉ c3");
System.out.println(c3.contemElemento(6)? "6 ∈ c3" :"6 ∉ c3");
// c4 = c1 ∩ c2 = {1, 3, 5}
Conjunto<Integer> c4 = c1.intersecao(c2);
System.out.println(c4.contemElemento(3)? "3 ∈ c4" :"3 ∉ c4");
System.out.println(c4.contemElemento(4)? "4 ∈ c4" :"4 ∉ c4");
// c5 = c1 - c2 = {2, 4}
Conjunto<Integer> c5 = c1.diferenca(c2);
System.out.println(c5.contemElemento(3)? "3 ∈ c5" :"3 ∉ c5");
System.out.println(c5.contemElemento(4)? "4 ∈ c5" :"4 ∉ c5");
// c6 = complemento(c1)
Conjunto<Integer> c6 = c1.complemento();
System.out.println(c6.contemElemento(2)? "2 ∈ c6" :"2 ∉ c6");
System.out.println(c6.contemElemento(7)? "7 ∈ c6" :"7 ∉ c6");
}
}