IDNLearn.com connects you with a global community of knowledgeable individuals. Our platform provides detailed and accurate responses from experts, helping you navigate any topic with confidence.
Sagot :
Answer:
Explanation:
The following code is written in Java. It creates a loop within a loop that plays the game 10 times. As soon as the inner loop tosses a Heads (represented by 1) the inner loop breaks and the cost of that game is printed to the screen. A test case has been made and the output is shown in the attached image below.
import java.util.Random;
import java.util.Scanner;
class Brainly {
public static void main(String[] args) {
int count = 0;
int loopCount = 0;
while (loopCount < 10) {
while (true) {
Random rand = new Random();
int coinFlip = rand.nextInt(2);
count++;
if (coinFlip == 1) {
System.out.println("Cost: $" + 2*count);
count = 0;
break;
}
loopCount++;
}
}
}
}
Thank you for contributing to our discussion. Don't forget to check back for new answers. Keep asking, answering, and sharing useful information. Thank you for trusting IDNLearn.com with your questions. Visit us again for clear, concise, and accurate answers.