Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
Problem !!
Whatās the code in Java to program the computer to select random numbers ?
5 Respostas
+ 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.
+ 8
//using Random class
https://code.sololearn.com/c6eVmt0l4qMr/?ref=app
+ 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.
+ 1
Iām trying to make it select between 3 string values
+ 1
Iāll try that... thank you for your help