Java - llenar vector si repetir numeros en java

 
Vista:

llenar vector si repetir numeros en java

Publicado por Jhon Quintero (2 intervenciones) el 05/11/2010 05:52:21
hola amigos!!!!!!

tengo que llenar un vector de 5 posiciones en java, bueno, aquí les paso lo que he hecho, pero no me funciona. Que tengo mal?

import java.io.*;

class v3
{

public static void main(String www[]) throws IOException
{

InputStreamReader entrada= new InputStreamReader (System.in);
BufferedReader lea= new BufferedReader(entrada);
int y=0;
int m=0;
int sw=0;
int w=0;
int cod=0;
int v[]= new int [5];

while(w<5)
{System.out.print("codigo: ");
cod=Integer.parseInt(lea.readLine());



if (w==0)
{v[w]=cod;w++;}
else
{

y=0;
sw=0;
while(y<w)
{if (v[w]==v[y])
{sw++;
}

y++;
}
if (sw==0)
{v[w]=cod;w++;System.out.println("ingresado");
}
else
{System.out.println("repetido.");

}


}

}
w=(0);


while (w<5)
{
System.out.print(" "+v[w]);
w++;





}


}

}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder