Desarrollar un programa que al ejecutarse genere y muestre en pantalla la
combinación de la lotería primitiva (seis números aleatorios diferentes entre 1 y 49)
/**
* @author Vogues
*/
import java.io.IOException;
public class Ej1 {
public static void main(String[] args) throws IOException{
//IOException evita que nos genere errores
//atributos
int vector[] = new int[5];
int i = 1, j;
//Queremos un valor aleatorio iniciado en 1 y max 49
vector[i] = (int) (Math.random() * (49) + 1);
//recorremos el vector 5 veces.
//ya que son los numeros aleatorios que quiero que muestre
for (i = 0; i < 5; i++) {
vector[i] =(int)(Math.random()*(49) + 1);
//Con esto eliminamos la provavilidad de que saldan numeros repetidos.
for (j = 0; j < i; j++) {
if (vector[i] == vector[j]) {
i--;
}
}
}
//Imprimimos los numeros aleatorios
for (i = 0; i < 5; i++) {
System.out.println(vector[i]);
}
}
}

No hay comentarios:
Publicar un comentario