mercredi 5 octobre 2016

Making a program that will generate 5 sets of 6 random numbers between 1 and 49, how can I make sure there aren’t any duplicates in each set?

I am making a program that will generate 5 sets of 6 random numbers to be used in the lottery however at the moment when the sets of numbers are printed they contain duplicates. How can I make it so every number in each set is unique?

import java.util.Arrays;

public class tasksTest {

    public static void main(String[] args) {


    System.out.println("Your lottery numbers are:");

    for(int i=1; i<6; i++){

        int[]lotteryNumbers = new int[6];

        for(int ii = 0; ii < lotteryNumbers.length; ii++){
            lotteryNumbers[ii] = (int)(Math.random()*49 + 1);
        }

        Arrays.sort(lotteryNumbers);
        System.out.println(Arrays.toString(lotteryNumbers));
    }
 }
}




Aucun commentaire:

Enregistrer un commentaire