Bom, primeiramente me desculpem por ter criado vários tópicos para tirar minhas dúvidas sobre o código da loteria, sem costume com foruns…
pra acompanhar melhor segue os links dos outros tópicos que criei:
O código abaixo sorteia X números com a opção de escolher X números pra não entrar no sorteio, parecido com o sistema deste link http://www.interney.net/lotofacil.php
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class Loteria {
public static void main(String[] args) throws Exception {
int qtdNumerosSorteio = 0;
int qtdNumerosExclusao = 0;
Scanner input = new Scanner(System.in);
System.out.println("Digite a quantidade de números que serão sorteados: ");
qtdNumerosSorteio = input.nextInt();
Integer[] numerosSorteio = new Integer[qtdNumerosSorteio];
for(int i = 0; i < qtdNumerosSorteio; i++) {
System.out.println("Informe os Numeros: ");
numerosSorteio[i] = input.nextInt();
}
System.out.println("Quantos números deseja excluir? ");
qtdNumerosExclusao = input.nextInt();
Integer[] numerosExclusao = new Integer[qtdNumerosExclusao];
for(int i = 0; i < qtdNumerosExclusao; i++) {
System.out.println("Informe os Numeros que serão excluidos: ");
numerosExclusao[i] = input.nextInt();
}
sortear(numerosSorteio, numerosExclusao);
}
public static void sortear(Integer [] arrayNumbers, Integer ... arrayExceptions) {
ArrayList<Integer> listNumbers = new ArrayList<Integer>();
listNumbers.addAll(Arrays.asList(arrayNumbers));
ArrayList<Integer> listExceptions = new ArrayList<Integer>();
listExceptions.addAll(Arrays.asList(arrayExceptions));
listNumbers.removeAll(listExceptions);
Random r = new Random();
while (!listNumbers.isEmpty()) {
int index = r.nextInt(listNumbers.size());
System.out.println(listNumbers.remove(index));
}
}
}
o problema é o seguinte: implementar ao código a opção de deixar X números fixos, assim como os excluidos, mas agora terão numeros fixos, excluidos, e o restante aleatorio
exemplo:
Lotofacil:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Numeros Excluidos:
5 10 24
Numeros Fixos:
11 13 20 25
aleatorios:
1 2 3 4 6 7 8 9 12 14 15 16 17 18 19 21 22 23
o sistema deverá sortear 15 numeros no total,
4 fixos e 11 aleatorios dentre os 18.
como faço pra implementar essa opção ao código?
Att.
Romário