Buscar este blog

martes, 14 de mayo de 2013

numeros aleatorios sin repetirse para java

import java.util.HashSet;

class ListaAleatoria {

public static void main(String args[]) {
HashSet t=new HashSet();

// 5 numeros aleatorios entre 0 y 49 sin repeticion
while (t.size()<5) {
Integer al=new Integer(new java.util.Random().nextInt(50));
t.add(al);
}

java.util.List lista=new java.util.ArrayList(t);
java.util.Collections.sort(lista);

// Se muestran los resultados
java.util.Iterator it=lista.iterator();
while (it.hasNext()) {
System.out.println((Integer)it.next());
}
}

}

1 comentario:

  1. LuckyClub Casino Site - Lucky Club Live Casino
    LuckyClub casino site is a trusted online gambling website. It luckyclub provides sports and poker to the best player and team in the world! Lucky Club is powered by a

    ResponderEliminar