ajaja45
Bovino Milenario
- Desde
- 20 Abr 2009
- Mensajes
- 1.173
- Tema Autor
- #1
Veran estoy elaborando una agenda electronica en java pero me tope con este codigo para buscar los contactos, pero no logro comprenderlo muy bien especificamente en lo que realizan las variables "i" y "j", no se si sea permitido que me orienten en esto, pero en caso de que pudieran se los agradeceria mucho.
if (opcion==2)
{
System.out.print("Nombre a buscar: ");
add = leer();
Iterator it = Contactos.iterator();
int i=0, j=0;
while (it.hasNext())
{
it.next();
if(Contactos.get(i).nom.equalsIgnoreCase(add))
{
j++;
System.out.println("Nombre: "+Contactos.get(i).nom+"\n"+
"Apellido Paterno: "+Contactos.get(i).ape+"\n"+
"Apellido Materno: "+Contactos.get(i).apem+"\n"+
"Email: "+Contactos.get(i).em+
"Sexo: "+Contactos.get(i).sexo+"\n"+
"Telefono: "+Contactos.get(i).tel+"\n"+
"Celular: "+Contactos.get(i).cel+"\n"+
"Nextel: "+Contactos.get(i).next+"\n"+
"Direccion: "+Contactos.get(i).dir);
System.out.println("Modificar: \n1.Si \n2.No");
while (opcion==2)
{
opcion = menu();
if (opcion==1)
{
System.out.print("Nombre: ");
Contactos.get(i).nom = leer();
System.out.print("Apellido Paterno: ");
Contactos.get(i).ape = leer();
System.out.print("Apellido Materno: ");
Contactos.get(i).apem = leer();
System.out.print("Sexo(Hombre/Mujer): ");
Contactos.get(i).sexo = leer();
System.out.print("Email: ");
Contactos.get(i).em = leer();
System.out.print("Telefono: ");
Contactos.get(i).tel = leer();
System.out.print("Celular: ");
Contactos.get(i).cel = leer();
System.out.print("Nextel: ");
Contactos.get(i).next = leer();
System.out.print("Direccion: ");
Contactos.get(i).dir = leer();
System.out.println("Hecho ✔");
break;
}
if(opcion==2){
break;
}
}
}
}
i++;
if (j==0)
{
System.out.println("El contacto " + add + " no se encuentra en la agenda");
}
}
if (opcion==2)
{
System.out.print("Nombre a buscar: ");
add = leer();
Iterator it = Contactos.iterator();
int i=0, j=0;
while (it.hasNext())
{
it.next();
if(Contactos.get(i).nom.equalsIgnoreCase(add))
{
j++;
System.out.println("Nombre: "+Contactos.get(i).nom+"\n"+
"Apellido Paterno: "+Contactos.get(i).ape+"\n"+
"Apellido Materno: "+Contactos.get(i).apem+"\n"+
"Email: "+Contactos.get(i).em+
"Sexo: "+Contactos.get(i).sexo+"\n"+
"Telefono: "+Contactos.get(i).tel+"\n"+
"Celular: "+Contactos.get(i).cel+"\n"+
"Nextel: "+Contactos.get(i).next+"\n"+
"Direccion: "+Contactos.get(i).dir);
System.out.println("Modificar: \n1.Si \n2.No");
while (opcion==2)
{
opcion = menu();
if (opcion==1)
{
System.out.print("Nombre: ");
Contactos.get(i).nom = leer();
System.out.print("Apellido Paterno: ");
Contactos.get(i).ape = leer();
System.out.print("Apellido Materno: ");
Contactos.get(i).apem = leer();
System.out.print("Sexo(Hombre/Mujer): ");
Contactos.get(i).sexo = leer();
System.out.print("Email: ");
Contactos.get(i).em = leer();
System.out.print("Telefono: ");
Contactos.get(i).tel = leer();
System.out.print("Celular: ");
Contactos.get(i).cel = leer();
System.out.print("Nextel: ");
Contactos.get(i).next = leer();
System.out.print("Direccion: ");
Contactos.get(i).dir = leer();
System.out.println("Hecho ✔");
break;
}
if(opcion==2){
break;
}
}
}
}
i++;
if (j==0)
{
System.out.println("El contacto " + add + " no se encuentra en la agenda");
}
}