ACS-1903 Midterm: TossCoin

87 views1 pages

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));

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents