diff --git a/src/gfn/marc/Lottozahlen.java b/src/gfn/marc/Lottozahlen.java index 9771a08..ec86287 100644 --- a/src/gfn/marc/Lottozahlen.java +++ b/src/gfn/marc/Lottozahlen.java @@ -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 lottozahlen = new ArrayList<>(6); - for (int i = 0; i <= 6; i++) { - lottozahlen.add((int) (Math.random() * 49) + 1); + Collection lottozahlenSet = new HashSet<>(6); + for (; lottozahlenSet.size() < 6;) { + lottozahlenSet.add((int) (Math.random() * 49) + 1); } + ArrayList lottozahlen = new ArrayList<>(lottozahlenSet); // Lottozahlen ausgeben System.out.println();