ayuda con sifras sin repetir en JAVA
Publicado por jose (3 intervenciones) el 27/02/2011 21:21:56
Hola, tengo el sgte problema: las sifras no deben de repetirse y con este codigo que he hecho no me resulta :(... hay alguien que me pueda ayudar?, gracias de antemano
public class s {
public static void main(String[] args) {
double[] s = new double[100];
s[0] = Math.round(Math.random()*10);
for(int i = 1; i < s.length; i++){
double temp = Math.round(Math.random()*10);
s[i]=temp;
int j=0;
while(s[j] == temp && j <= i ){
temp = Math.round(Math.random()*10);
s[i]=temp;
}
}
for (int i = 0; i < s.length; i++){
System.out.println(s[i]);
}
}
public class s {
public static void main(String[] args) {
double[] s = new double[100];
s[0] = Math.round(Math.random()*10);
for(int i = 1; i < s.length; i++){
double temp = Math.round(Math.random()*10);
s[i]=temp;
int j=0;
while(s[j] == temp && j <= i ){
temp = Math.round(Math.random()*10);
s[i]=temp;
}
}
for (int i = 0; i < s.length; i++){
System.out.println(s[i]);
}
}
Valora esta pregunta


0