0

Problem !!

What’s the code in Java to program the computer to select random numbers ?

7th Mar 2018, 8:41 AM
chris olet
5 RĂ©ponses
+ 2
The method to generate random double values is Math.random(). It returns a random double between 0.1 and 1.0. If you need an integer value you need to apply a cast to its result.
7th Mar 2018, 8:43 AM
Sir Drake
Sir Drake - avatar
7th Mar 2018, 1:17 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 2
Apply the method as the value of a double variable (let's say "double x"). Then make some if statements saying if you x values is less or bigger than 0.4 the value of an int value (lets say "int y") would be 1, if its less than 0.7 and bigger than 0.3 the value of y is 2, and else the value of y is 3. Then make a switch case with the 3 options of the y variable values, with your 3 strings as results.
7th Mar 2018, 8:51 AM
Sir Drake
Sir Drake - avatar
+ 1
I’m trying to make it select between 3 string values
7th Mar 2018, 8:45 AM
chris olet
+ 1
I’ll try that... thank you for your help
7th Mar 2018, 10:11 AM
chris olet