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