I'm trying to write a program that does the following:
A number is designated as int win = 1.
Then a random number is generated.
If the number matches the winning number (1) then a counter is added.
What my program continues to do is cotinually add rather than obey the if statement.
Basically if number matches 1, a counter i added and this loop continues until 20 random numbers.
Code:import java.io.IOException;
import java.io.PrintWriter;
import java.io.File;
import java.util.Random;
public class BottleCapPrize
{
public static void main (String [ ] args) throws IOException
{
PrintWriter outFile = new PrintWriter(new File("montecarlo.txt"));
int number = 0;
int Matches = 0;
Random randNumList = new Random();
int win = 1;
for(int cap = 1; cap <= 20; cap++)
{
number = randNumList.nextInt(6);
if(win != number)
Matches++;
System.out.println(Matches);
}
}
}
