unable to generate a random number
Hi,
Anyone can help? I cant complie the following program.
error -- cannot file symbol method netInt()
Thanks!
import java.util.*;
public class Random
{
public static void main(String[] args)
{
Random generator = new Random();
int r = generator.nextInt();
}
}
if that is the exact code, then of course you have no way to even test if a random number was generated. what you have there should generate a random int. try printing it out or something to determine if it did it right.
import java.util.*;
public class RanNum
{
public static void main(String[] args)
{
Random generator = new Random();
int r = generator.nextInt();
System.out.println(r);
}
}
or to test the randomablility
import java.util.*;
public class RanNum
{
public static void main(String[] args)
{
Random generator = new Random();
for(int r = 0; r < 10; r++)
System.out.println(generator.nextInt());
}
}