Zargoon
June 23rd, 2009, 07:31 PM
So I'm fairly new to programming, and I'm trying to create a simply program. For this program I need to be able to generate a 'random' integer. Here's how I went about trying to do this:
I created a "Randomint" class that is supposed to make a random integer between 0 and 10.
import java.util.Random;
public final class Randomint {
public static final void main(String... aArgs) {
Random randomGenerator = new Random();
int rint = randomGenerator.nextInt();
int random_number = rint % 10;
if (random_number < 1) random_number = random_number + 10;
}
}
And here's my main argument:
public class Problemgenerator {
public static void main(String[] args) {
Randomint rint = new Randomint();
System.out.println(rint);
}
}
I think it should work, but when I run it I get an output like:
math.Randomint@158c662c
Which isn't very helpful, obviously.
Well thanks in advance for any light you guys can shed on this!
I created a "Randomint" class that is supposed to make a random integer between 0 and 10.
import java.util.Random;
public final class Randomint {
public static final void main(String... aArgs) {
Random randomGenerator = new Random();
int rint = randomGenerator.nextInt();
int random_number = rint % 10;
if (random_number < 1) random_number = random_number + 10;
}
}
And here's my main argument:
public class Problemgenerator {
public static void main(String[] args) {
Randomint rint = new Randomint();
System.out.println(rint);
}
}
I think it should work, but when I run it I get an output like:
math.Randomint@158c662c
Which isn't very helpful, obviously.
Well thanks in advance for any light you guys can shed on this!