samedi 4 décembre 2021

how do I generate random numbers then add to a set in Java?

I want to make an empty set, then add N- many random numbers between 1 and 100 to a set. I used count to be up to 10 but I'm not sure if that is correct. I also am not sure how to add the generated numbers to the HashSet.

    //generates random birthdays
    Random coins = new Random();
    int number;

    for (int count = 1; count <= 10; count++){
        number = 1+coins.nextInt(100);
    }
      HashSet<Integer> hash = new HashSet<Integer>();
      hash.add(number);



Aucun commentaire:

Enregistrer un commentaire