This question already has an answer here:
Alright so as the title says, I need some help creating a random number generator to output 5 random digits. I have already compiled what I believed would work but I keep running into a problem and don't know how to correct it. Here is what I have:
public class Number {
public static void main(String[] args) {
log("5 randomly generated numbers from 0 to 99");
Number randomGenerator = new Number();
for (int idx = 1; idx <= 5; ++idx) {
int randomInt = randomGenerator.nextInt(100);
log("Random Number: " + randomInt);
}
}
private int nextInt(int i) {
return 1;
}
private static void log(String aMessage) {
System.out.println(aMessage);
}
}
The problem occurs with the '{return 1;} part, whenever I run it, the only number it generates is 1. I'm not sure how to correct this, any feedback is greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire