Auf Thema antworten

Also ist das keine "wichtige" Aufgabe für dich sondern nur so zum Spaß :p

Mein Lösungsvorschlaf wäre dieser hier. Finde das zwar überhaupt nicht schön da man 2x break drin hat aber naja! :D

Ob der 100% richtig ist weiß ich nicht das war nur meine Idee :p


[SPOILER="..."]

[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, 18, 23, 32, 33, 34, 35};

        Random zufall = new Random();

        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;

                }

            }

            if(i == lotto.length-1) {

                for(int k = 0; k<i;k++)

                    if(lotto[k] == lotto2[k])

                        break;

                    else {

                       

                        lotto[i] = lotto2[(int) (Math.random()*7)];

                    }

            }

        }

        Arrays.sort(lotto);

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

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

    }

}[/CODE]

[/SPOILER]




Jeder fängt doch mal klein an :) aber dann kann ich ja hier wieder meine 1000 Fragen los werden :p


LG



Oben