Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions

Question

Understand why customers complain.

Answered: 1 week ago