Mój program odczytuje ze strumienia ile razy rzucam monetą , ale chciałbym dodać do programu dodatkowy parametr k - prawdopodobieństwo wyrzucenia reszki. I na tym utknąłem.
public static void main (String[] args) {
Scanner scan = new Scanner (System.in);
Random coin;
coin = new Random();
int count = 0, heads = 0, tails = 0;
int number_flips, flip_result;
System.out.print ("Enter the number of flips: ");
number_flips = scan.nextInt();
while (count < number_flips) {
flip_result = Math.abs (coin.nextInt()) % 2;
if (flip_result == 0)
heads = heads + 1;
else
tails = tails + 1;
count = count + 1;
}
System.out.println ("The number of heads is " + heads);
System.out.println ("The number of tails is " + tails);
}
Jak operować prawdopodobieństwem wyrzucenia reszki z klawiatury?? (zwiększać je ,czy zmniejszać.)
public static float k;
System.out.print("Podaj k (Prawdopodobieństwo wyrzucenia reszki ): ");
k = input.nextFloat();
niech k będzie tym prawdopodobieństwem.
dodanie znacznika <code class="java">
- @furious programming