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();

}

}

[338 byte] By [superdolphinea] at [2007-10-3 8:30:02]
# 1
Rename your class to something other than random.
CaptainMorgan08a at 2007-7-15 3:37:00 > top of Java-index,Java Essentials,Java Programming...
# 2
Did you spell the method correctly?Remember capitalization of characters is important.My eyesight is going.... forget thisMessage was edited by: camickr
camickra at 2007-7-15 3:37:00 > top of Java-index,Java Essentials,Java Programming...
# 3
Use full qualified names to prevent collusions with your own Random class:java.util.Random generator = new java.util.Random();
bytoa at 2007-7-15 3:37:00 > top of Java-index,Java Essentials,Java Programming...
# 4
I rename the Class, but still have the same error!import java.util.*;public class RanNum{public static void main(String[] args){Random generator = new Random();int r = generator.nextInt();}}
superdolphinea at 2007-7-15 3:37:00 > top of Java-index,Java Essentials,Java Programming...
# 5
What is the error? Is the code you posted your exact code?
CaptainMorgan08a at 2007-7-15 3:37:00 > top of Java-index,Java Essentials,Java Programming...
# 6

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());

}

}

sosleepya at 2007-7-15 3:37:00 > top of Java-index,Java Essentials,Java Programming...
# 7
Are you sure that the last set of code you posted doesn't work for you? It works on my computer... If that's the only error it's giving, then maybe something went wrong with your Java install?
Zyphona at 2007-7-15 3:37:00 > top of Java-index,Java Essentials,Java Programming...
# 8
Make sure you are recompiling after every change before you test it. I say this because the error you gave us occurred because you mistyped nextInt as netInt, yet the code you posted has it right.
Zyphona at 2007-7-15 3:37:00 > top of Java-index,Java Essentials,Java Programming...
# 9
Did you delete the Random.class file from your directory?
camickra at 2007-7-15 3:37:00 > top of Java-index,Java Essentials,Java Programming...
# 10
After delete the Random.class, I can compile it now!!!Thanks all!!!!!
superdolphinea at 2007-7-15 3:37:00 > top of Java-index,Java Essentials,Java Programming...