diff --git a/src/gfn/marc/Lottozahlen.java b/src/gfn/marc/Lottozahlen.java index c78483c..9771a08 100644 --- a/src/gfn/marc/Lottozahlen.java +++ b/src/gfn/marc/Lottozahlen.java @@ -2,6 +2,7 @@ package gfn.marc; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.Scanner; public class Lottozahlen { @@ -12,7 +13,7 @@ public class Lottozahlen { boolean eingabeKorrekt = false; // Lottoschein ausfüllen - ArrayList lottoschein = new ArrayList<>(6); + HashSet lottoschein = new HashSet<>(6); while (!eingabeKorrekt) { System.out.println("Bitte geben Sie sechs, mit Kommata getrennte, Lottozahlen (1 - 49) ein. " + "(Beispiel: \"6,12,29,34,40,46\")"); @@ -25,7 +26,13 @@ public class Lottozahlen { lottoschein.add(Integer.parseInt(zahl)); } - eingabeKorrekt = true; + // Prüfung: Doppelte zahlen? + if (lottoschein.size() == 6) { + eingabeKorrekt = true; + } else { + System.err.println("Doppelte Zahlen!"); + } + } else { System.err.println("Ungültige Zahlen!"); } @@ -51,13 +58,13 @@ public class Lottozahlen { // Lottoschein auswerten ArrayList richtige = new ArrayList<>(); - for (int zahl : lottoschein ) { + for (int zahl : lottoschein) { if (lottozahlen.contains(zahl)) { richtige.add(zahl); } } - + // Ergebnis ausgeben Collections.sort(richtige); System.out.println(richtige.isEmpty() ? "Sie haben leider keine richtige Zahl!" : "Sie haben " + richtige.size() + " Richtige: ");