How to generate random number in java?
Printable View
How to generate random number in java?
Math.random()
Will generate a random number between 0 and 1.
:)
Or you can instantiate an object of Random
import java.util.Random;
Random x = new Random();
x.nextInt(5); returns an int value [0,5)
but it gives error
impot java.util.Ramdom
class a
{
public static void main()
{
Random i=new Random();
}
}
impot???
Ramdom???
I'm guessing you just typed that in the thread, so post the error you get. If you didn't, check your spelling :)
Also thought you needed String[] args as input in the main procedure.