A lottery requires that you select six different numbers


The Lottery Problem:

A lottery requires that you select six different numbers from the integers 1 to 49. Write a Java program that will do this for you and generate five sets of six numbers as a result.

For generating random numbers you can use the random() static method of class Math. It returns a double so you will need to cast it as an integer. If you set the range to 49, you can generate a random number between 1 and 49 through:
number = (int) ( range * Math.random() ) + 1;

Note that you need 5 sets of numbers and in each set you have should have six different numbers. There should not be duplicate numbers within each set. Of course the same number can occur in multiple sets, but within the same set of 6 numbers it should only occur once, if at all.

Here is an example of a valid set of numbers: 5, 41, 3, 9, 22, 30

Here is an example of an invalid set of numbers: 15, 8, 19, 33, 8, 21

It is invalid because the number 8 appears twice.

Solution Preview :

Prepared by a verified Expert
Game Theory: A lottery requires that you select six different numbers
Reference No:- TGS01254255

Now Priced at $20 (50% Discount)

Recommended (93%)

Rated (4.5/5)