Welcome to Westonci.ca, where finding answers to your questions is made simple by our community of experts. Get expert answers to your questions quickly and accurately from our dedicated community of professionals. Discover in-depth answers to your questions from a wide network of professionals on our user-friendly Q&A platform.
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++;
}
}
}
}
We hope our answers were useful. Return anytime for more information and answers to any other questions you have. Your visit means a lot to us. Don't hesitate to return for more reliable answers to any questions you may have. Thank you for visiting Westonci.ca, your go-to source for reliable answers. Come back soon for more expert insights.