Simulate playing a game where you flip two coins if both coi
Solution
import java.util.Random;
public class CoinsGame {
private static boolean CheckWinChance() {
if (FlipTwoCoins()) {
return true;
}
return FlipThreeCoins();
}
private static boolean FlipTwoCoins() {
Random r = new Random();
if (r.nextInt(2) == r.nextInt(2))
return true;
return false;
}
private static boolean FlipThreeCoins() {
Random r = new Random();
int a = r.nextInt(2), b = r.nextInt(2), c = r.nextInt(2);
if (a == b && b == c)
return true;
return false;
}
public static void main(String[] args) {
int winCount=0;
for (int i = 0; i < 100; i++) {
if (CheckWinChance()) {
winCount++;
}
}
System.out.println(winCount);
}
}
