Diferencia de conjuntos
Publicado por Andres Camelo (1 intervención) el 04/11/2019 23:11:07
Buenas tardes
Estoy haciendo un ejercicio sobre conjuntos pero me no me esta funcionando.
Esa es la clase diferencia y me dice que hay un error sobre esta parte
Por favor ayuda, gracias.
Estoy haciendo un ejercicio sobre conjuntos pero me no me esta funcionando.
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
53
54
55
56
57
58
59
60
61
62
package conjuntos;
/**
*
* @author julio
*/
public class Diferencia {
private Conjunto c1;
private Conjunto c2;
public Diferencia() {
c1 = new Conjunto(1);
c2 = new Conjunto(1);
}
public Conjunto getC1() {
return c1;
}
public void setC1(Conjunto c1) {
this.c1 = c1;
}
public Conjunto getC2() {
return c2;
}
public void setC2(Conjunto c2) {
this.c2 = c2;
}
public Conjunto diferencia() {
int tamaño = c1.getElementos().length;
for (int i = 0; i < c1.getElementos().length; i++) {
for (int j = 0; j < c2.getElementos().length; j++) {
if (c1.getElementos()[i].compareTo(c2.getElementos()[j]) == 0) {
tamaño--;
}
}
}
Conjunto c1Dc2 = new Conjunto(tamaño);
c1Dc2.setNombre(c1.getNombre() + " / " + c2.getNombre());
c1Dc2.inicializarArreglo();
int k = 0;
int b = 0;
for (int i = 0; i < c1.getElementos().length; i++) {
for (int j = 0; j < c2.getElementos().length; j++) {
if (c1.getElementos()[i].compareTo(c2.getElementos()[j]) != 0) {
c1Dc2.getElementos()[k] = c1.getElementos()[i];
k++;
}
}
}
return c1Dc2;
}
}
Esa es la clase diferencia y me dice que hay un error sobre esta parte
1
2
3
4
5
6
7
8
9
10
11
12
for (int i = 0; i < c1.getElementos().length; i++) {
for (int j = 0; j < c2.getElementos().length; j++) {
if (c1.getElementos()[i].compareTo(c2.getElementos()[j]) != 0) {
c1Dc2.getElementos()[k] = c1.getElementos()[i];
k++;
}
}
}
return c1Dc2;
}
}
Por favor ayuda, gracias.
Valora esta pregunta


0