Vermeidung doppelter Lottozahlen hinzugefügt
This commit is contained in:
parent
c41c0d5c4c
commit
5dd6d0d949
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue