Código de Java - Conjuntos

1.0

Publicado el 12 de Octubre del 2020gráfica de visualizaciones de la versión: 1.0
1.848 visualizaciones desde el 12 de Octubre del 2020
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import java.util.*;
import java.io.*;
 
public class Conjuntos {
 
static  boolean A[]=new boolean  [21];
static boolean B[]=new boolean  [21];
private int cad[]=new int [20];
static boolean c[]=new boolean  [21];
 
public Conjuntos()
{
	for(int i=0;i<=20;i++)
	{
	 A[i]=false;
	 B[i]=false;
	 c[i]=false;
	}
}
 
public void Fijar(int uno[], int dos[], int x, int y)
{
 int n=0, i=0;
  for(i=0; i<x; i++)
   {
    n=uno[i];
    A[n]=true;
   }
  for(i=0; i<y; i++)
   {
    n=dos[i];
    B[n]=true;
   }
}
 
public void subconjunto()
{
  int i=0, g=0;
   for (i=0;i<20;i++)
    if(B[i]==true)
     if(A[i]!=true)
    	g=1;
   if (g==1)
     System.out.println("\n\t\tB no es subconjunto de A  ");
   else
     System.out.println("\n\t\tB es subconjunto de A  ");
}
 
public void union()
{
 int 	i=0, j=0;
  for (i=0;i<=20;i++)
   {
    if(A[i]==true || B[i]==true)
     c[i]=true;
    else
     c[i]=false;
   }
 
   for (i=0;i<=20;i++)
   {
    if (c[i]==true)
     {
     	cad[j]=i;
    	j++;
     }
   }
   System.out.print("\n\nEl conjunto resultante de la union es:");
   for(int z=0;z<j;z++)
   System.out.print(" "+cad[z]);
}
 
public void interseccion()
{
 int i=0,j=0;
  for (i=0;i<=20;i++)
   {
    if(A[i]==true && B[i]==true)
     c[i]=true;
    else
     c[i]=false;
   }
  for (i=0;i<=20;i++)
   {
    if (c[i]==true)
     {
     	cad[j]=i;
    	j++;
     }
   }
   System.out.print("\n\nEl conjunto resultante de la interseccion es:");
   for(int z=0;z<j;z++)
   System.out.print(" "+cad[z]);
}
 
public void diferencia()
{
 int 	i=0, j=0;
  for (i=0;i<=20;i++)
   {
    if((A[i]==true)&&( B[i]==false))
     {
     	c[i]=true;
     }
    else
     c[i]=false;
   }
   for (i=0;i<=20;i++)
   {
    if (c[i]==true)
     {
    	cad[j]=i;
    	j++;
     }
   }
   System.out.print("\n\nEl resultado de la diferencia es:  ");
    for(int z=0;z<j;z++)
	System.out.print(" "+cad[z]);
}
 
public static void main (String[] args) throws IOException
{
  BufferedReader teclado = new BufferedReader(new InputStreamReader (System.in));
  Scanner valores = new Scanner(System.in);
  StringTokenizer x;
  int o;
  //
  do
  {
  System.out.println("QUE TAMAÑO TIENE EL PRIMER CONJUNTO: ");
   int i = valores.nextInt();
  System.out.println("QUE TAMAÑO TIENE EL SEGUNDO CONJUNTO: ");
   int j = valores.nextInt();
   int[] a1=new int[i];
   int[] b1=new int[j];
  System.out.println("Introduce los valores del primer conjunto(SEPARADOS CON ESPACIOS): ");
  String a = teclado.readLine();
   x=new StringTokenizer(a);
    if(x.countTokens()!= i)
  System.out.println("Los valores no satisfacen el arreglo");
   for(int z=0;z<i;z++)
    a1[z]=Integer.parseInt(x.nextToken());
 
  System.out.println("Introduce los valores del primer conjunto(SEPARADOS CON ESPACIOS): ");
  String b = teclado.readLine();
   x=new StringTokenizer(b);
  if(x.countTokens()!= j)
   System.out.println("Los valores no satisfacen el arreglo");
    for(int z=0;z<j;z++)
     b1[z]=Integer.parseInt(x.nextToken());
      System.out.println("\nEl primer conjunto leido es="+a+", De tamaño="+i+"\n\nEl segundo conjunto leido es="+b+", De tamaño="+j);
 
//LLAMaDAS A LOS METODOS
Conjuntos Con=new Conjuntos();
 
Con.Fijar( a1, b1, i, j);
Con.subconjunto();
Con.interseccion();
Con.diferencia();
Con.union();
 
System.out.println("\n\nDesea hacer otra operacion 1.-Si/2.-NO");
 o=valores.nextInt();
}while(o==1);
}
}



Comentarios sobre la versión: 1.0 (0)


No hay comentarios
 

Comentar la versión: 1.0

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s6587