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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started