I am making a coin flip simulator, but I have a problem with the random values. I need to make a random value that changes every time the while-loop starts again.
System.out.println("How many times do I flip the coin?");
int repetition;
int heads = 0;
int tails = 0;
Scanner amount_of_times = new Scanner(System.in);
repetition = amount_of_times.nextInt();
double luck = (Math.random());
do {
if (luck > 0.5)
heads++ ;
else
tails++ ;
repetition --;
} while (repetition > 0);
System.out.println("The amount of heads was " + heads + ", meanwhile the amount of tails was " + tails + ".");
amount_of_times.close();
}
}
Aucun commentaire:
Enregistrer un commentaire