Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Java program Write a static method named sameFlip that accepts a Random object as a parameter. Your method should flip a coin until the same

Java program

Write a static method named sameFlip that accepts a Random object as a parameter. Your method should flip a coin until the same result occurs twice in a row. In other words, if a head is flipped followed by another head or if a tail is flipped followed by another tail, your method should end. You should use the Random object to give an equal chance to a head or tail appearing. Each time the coin is flipped, print H for heads or T for tails.

For example, if the following variable is initialized:

Random r = new Random();

Here are some sample calls along with possible output:

Call

Output

sameFlip(r);

HTHH

sameFlip(r);

HTHTT

sameFlip(r);

TT

sameFlip(r);

THTHTHH

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions