samedi 7 décembre 2019

Generates 10 non-duplicate random integers within an Array

package array;

import java.security.SecureRandom;
import java.util.ArrayList;

public class Array {

    public static void main(String[] args) {
        SecureRandom rand = new SecureRandom();
        int random;
        int count = 0;
        ArrayList<Integer> arrayList = new ArrayList(10);

        while (count != 10) {
            random = rand.nextInt(21);
            if (!arrayList.contains(random)) {
                arrayList.add(random);
                count++;
            }
        }
        System.out.println(arrayList + "\n");
    }
}



Aucun commentaire:

Enregistrer un commentaire