40.4k views
4 votes
Write a method called threeHeads that repeatedly flips a coin until a coin

1 Answer

14 votes

Answer:

public void threeHeads() {

Random r = new Random();

int count = 0;

while(count < 3) {

boolean head = r.nextBoolean();

if(head) {

System.out.print("H ");

count++;

} else {

System.out.print("T ");

count = 0;

}

}

System.out.println("\\Three heads in a row!");

}

Step-by-step explanation:

Use GitHub

User Paddotk
by
5.9k points