let me start out by saying I'm very new to Java. Most of the code and functions I've seen here and elsewhere is either way above my head, or I just haven't learned it yet. That being said, I have yet to find a solution to this issue simply by Googling for answers.
I need to make a random generator within a "for" loop that will run 100, 1,000,000, and 1,000,000,000 times. The idea is to simulate a roulette wheel spinning that many times, and then calculating:
- How many reds appear.
- How many blacks appear.
- How many times a number appears twice in a row.
- How many times a number appears three times in a row.
- Longest string of even numbers.
- Longest string of odd numbers.
I have already coded an if/else if statement to assign the numbers 0-36 a color, and written a very basic for loop containing a random generator and a getter for the colors (I haven't figured out exactly how I'm going to count the strings of recurring numbers). My loop should reiterate 100 times, and according to everything I've read, it should. However, when it prints, it only prints 47 lines. This leads me to believe my loop is only initializing 47 times. If this is the case, what am I doing wrong?
import java.util.Random;
public class RouletteGenerator
{
public static void main(String[] args) {
RouletteWheel wheelGenerator = new RouletteWheel();
Random generator = new Random();
//FIELDS
int random;
int red = 0;
int black = 0;
int two = 0;
int three = 0;
int even = 0;
int odd = 0;
int lastNumber = 0;
int lastNumber2 = 0;
for (int i = 0; i <= 100; i++) {
random = generator.nextInt(37);
wheelGenerator.setNumber(random);
String numberColor = wheelGenerator.getColor();
System.out.println("Your random number is: " + random + " - " + numberColor);
}
}
}
Aucun commentaire:
Enregistrer un commentaire