Hi i m new in java..
i have to solve this..
write a programme to display random choice from a set of six choices,scrambled, eggs, waffles etc.....
kindly help me....i m having huge problem...

7 Years
Discussion Span
Last Post by sirlink99

also you could use an array to contain your choices and use the random number to index into the array.


you could also use

Math.random ();

and then compare the generated number to if statements, each of which contain one option.


i know Math.random can solve this..
but the problem is how to take initialize six choices?
could u plz tell me code?


how to take initialize six choices

Call the random number generater until you get six unique numbers.
Use an array of booleans the size of the total number of different items to chose from.
When the next random number is generated, test if it was chosen before by looking at the boolean array[index] value, if not set, set it and use that number.
If the set, reject that number because it was already used and get another random number and test that one as above

Edited by NormR1: n/a


You can use

Math.floor((Math.random () * 6)) // to get values from 0.0 - 5.0 or
Math.floor((Math.random () * 6) + 1) // to get values from 1.0 - 6.0

and then just cast it as an it to get it a whole value if it matters to you.

(int) Then the rest of the line

Edited by sirlink99: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.