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...
Regards..
Farhad

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

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.