Question: java For this exercise, you must create a String of 80 H's and T's, where each character is chosen at random. You will then check

 java For this exercise, you must create a String of 80

java

For this exercise, you must create a String of 80 H's and T's, where each character is chosen at random. You will then check whether the string contains a string of 6 consecutive H's. This simulates flipping a coin 80 times and checking whether there is any time when the coin comes up Heads six times in a row. The program for this exercise can be called SixHeads. You will need another counting loop to count the 80 coin flips. Note that you can add a character, ch, onto a string, str, by saying str=str+ch But hopefully, you be using better variable names than str and ch! You need to think about what the iitial value of the string should be. What should it be, before you have added any letters onto it? And note that you can use str. indexOf ("HHH") to test whether HHHHHH occurs in str. The value of this expression is -1 if HHHH does not occur in str. At the end of the program, you should print out the string of 80 H's and T's, and you should report the results of the test. For example: HHHHHH does occur in the string. The probability that HHHHHH occurs is somewhere close to 1/2. Write an additional program that runs the same experiment without printing anything 1,000,000 times and reports the fraction of experiments in which the string contained HHHH

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!