Vermeidung doppelter Lottozahlen hinzugefügt

This commit is contained in:
Marc Koch 2020-04-09 09:03:29 +02:00
parent c41c0d5c4c
commit 5dd6d0d949
1 changed files with 5 additions and 7 deletions

View File

@ -1,9 +1,6 @@
package gfn.marc;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
import java.util.*;
public class Lottozahlen {
@ -39,10 +36,11 @@ public class Lottozahlen {
}
// Lottozahlen ziehen
ArrayList<Integer> lottozahlen = new ArrayList<>(6);
for (int i = 0; i <= 6; i++) {
lottozahlen.add((int) (Math.random() * 49) + 1);
Collection<Integer> lottozahlenSet = new HashSet<>(6);
for (; lottozahlenSet.size() < 6;) {
lottozahlenSet.add((int) (Math.random() * 49) + 1);
}
ArrayList<Integer> lottozahlen = new ArrayList<>(lottozahlenSet);
// Lottozahlen ausgeben
System.out.println();