In this program, you'll see how using a do-while loop
might be better than a while
loop.
The code I have provided does not compile. Once you fix it, it will look roughly like this.
You flip a coin and it is... TAILS Would you like to flip again (y/n)? y You flip a coin and it is... HEADS Would you like to flip again (y/n)? y You flip a coin and it is... HEADS Would you like to flip again (y/n)? n
Assignments turned in without these things will receive no credit.
while
loop tests if again.equals("y")
, but the variable again
doesn't have a value at first. Give it a value so that the code will compile and
the loop will run at least once.
while
loop to a do-while loop. Make sure it still works.
String again;
Does the program still work? Why or why not?
(Answer in a comment.)
©2013 Graham Mitchell
This assignment is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.