samedi 26 mars 2016

In java how can i randomize and int in an array

Hi i am just learning java and want to write a sort of vocabulary trainer. It is working but i want to give the questions in a random order. The trainer pics a list from an external file and splits the file in two parts. It is asking as long the next line isn't null.

for (int i = 0; (zeile = br.readLine()) != null; i++) { 
        splitted = zeile.split(";");                     
        eng[i] = splitted[0];                          
        ger[i] = splitted[1];

then i am asking for the vocabulary. But as you can see its always in the same order. I don't know how i can correctly randomize the list before the asking part.

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

        correct = false;
        while (!correct) {

            System.out.print(eng[j] + " bedeutet: ");

            gerEingabe = vokabel.nextLine(); 

            if (gerEingabe.equals(ger[j])) {
                System.out.println("Das ist Korrekt. Auf zur nächsten Aufgabe.");
                correct = true;
            } else {
                System.out.println("Das war leider Falsch. Bitte versuche es noch ein mal.");

It would be nice if someone can help me with this.




Aucun commentaire:

Enregistrer un commentaire