ACS-1903 Midterm: TossCoin
Document Summary
* toss a coin until there are 2 consecutive heads. * @author () public class tosscoin public static void main(string[] args){ System. out. println("tossing a coin until there are 2 consecutive. // a random number generator is used to simulate tossing a coin. // this program associates heads with the random boolean true. // and associates tails with the random boolean false. // variables for keeping track of the previous and current coin tosses boolean previouscointoss, currentcointoss; // first toss is before loop begins currentcointoss = coin. nextboolean(); // the do-while executes for all coin tosses after the first toss do { // remember the previous coin toss previouscointoss = currentcointoss; // now toss the coin again currentcointoss = coin. nextboolean(); // repeat as long as the last two coin tosses are not both heads while (! (previouscointoss && currentcointoss));