Auf Thema antworten

So sollte es gehen aber ohne den Vorgegeben Rahmen.

Das Array füllen und prüfen ob die Zahl von Lotto2 vorhanden sind wenn nein füge an eine Random Stelle eine Random Zahl aus Lotto2 ein.


[CODE=java]import java.util.Arrays;

import java.util.Random;


public class Zahlen8 {

    private static final int ANZAHL = 8;


    public static void main(String[] args) {

        int[] lotto = new int[ANZAHL];

        int[] lotto2 = { 5, 10, 15, 20, 25, 30, 35, 40 };

        Random zufall = new Random();

        boolean isDrin = false;

        for (int i = 0; i < lotto.length; i++) {

            lotto[i] = zufall.nextInt(50) + 1;

            for (int j = 0; j < i; j++) {

                if (lotto[j] == lotto[i]) { // die Zahlen sollen sich nicht wiederholen

                    i--;

                    break;

                }

            }

        }

       

        for(int i = 0; i < lotto.length; i++)

            for(int j = 0; j < lotto2.length; j++)

                if(lotto[i] == lotto2[j])

                    isDrin = true;


        if(!isDrin)

            lotto[(int) (Math.random()*lotto.length-1)] = lotto2[(int) (Math.random()*lotto2.length-1)];

       

        Arrays.sort(lotto);

        for (int i = 0; i < lotto.length; i++)

            System.out.printf("%3d", lotto[i]);

    }

}[/CODE]


Nicht schön aber selten :D


Vielleicht kann es ja jemand noch mit dem Programm Rahmen lösen. Dafür fehlt mir jetzt die Zeit :/


LG



Oben