Question: *JAVA Write code to generate 6 unique integers for a lottery game. how to generate random numbers ? Math.random() - gives a number between 0

*JAVA

Write code to generate 6 unique integers for a lottery game.

how to generate random numbers ?

Math.random() - gives a number between 0 and 1 (i.e a number with decimal value)

(int) - using this before a number is how one tries to change from another numerical type to int data type

int x = (int) 3.14 makes the value of x to be 3

int x = (int) (3.14 * 100) makes the value of x to be 314

how to find if a number is unique ?

We do the following process until we get 6 unique numbers in the array.

Generate a random number.

Check the randomly generated number against each element in the array - use a Boolean variable as a flag.

Check the flag and decide to add the random number to array or not.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!