Ver Mensaje Individual
  #4 (permalink)  
Antiguo 19/10/2009, 22:16
Avatar de fradve
fradve
 
Fecha de Ingreso: abril-2009
Mensajes: 157
Antigüedad: 15 años, 1 mes
Puntos: 7
De acuerdo Respuesta: Problema con Método.

Hola, creo que esto es lo que quieres, es tu mismo código con ciertas modificaciones:

Código java:
Ver original
  1. public class Conjunto
  2. {
  3.     public static boolean repite(String C[],String dato)
  4.     {
  5.         boolean bandera=false;
  6.        
  7.         for(int i=0;i<C.length;i++)
  8.         {
  9.             if(dato.equals(C[i]))
  10.             {
  11.                 bandera=true;
  12.                 i=C.length;
  13.             }
  14.         }
  15.         return bandera;
  16.     }
  17.    
  18.     public static void main(String[] args)
  19.     {
  20.         String[] A=new String[10];
  21.         String[] B=new String[10];
  22.         String dato;
  23.        
  24.         for(int i=0;i<A.length;i++)
  25.         {
  26.             System.out.println("Inserte el valor del conjunto A en la posición [ " + (i+1) + "] :");
  27.             dato= Leer.dato();
  28.            
  29.             if(!repite(A,dato))
  30.                 A[i]=dato;
  31.             else
  32.             {
  33.                 System.out.println("EL DATO INGRESADO YA EXISTE");
  34.                 i--;
  35.             }
  36.         }
  37.        
  38.         for(int i=0;i<B.length;i++)
  39.         {
  40.             System.out.println("Inserte el valor del conjunto B en la posición [ " + (i+1) + "] :");
  41.             dato= Leer.dato();
  42.            
  43.             if(!repite(B,dato))
  44.                 B[i]=dato;
  45.             else
  46.             {
  47.                 System.out.println("EL DATO INGRESADO YA EXISTE");
  48.                 i--;
  49.             }
  50.         }
  51.     }
  52. }

No sé si lo mismo querías para el B pero igual puedes modificarlo. Espero te sea de ayuda.
__________________
En programación hay mil y un formas de hacer lo mismo...