Assignemnt #70 and Flip Again?
Code
///Name: Ben Borglin
///Period: 6
///Program name: Flaip again?
///file name: FlipAgain.java
///Date Finsihed: 10/23/15
import java.util.Random;
import java.util.Scanner;
public class FlipAgain
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random rng = new Random();
String again;
do
{
int flip = rng.nextInt(2);
String coin;
if ( flip == 1 )
coin = "HEADS";
else
coin = "TAILS";
System.out.println( "You flip a coin and it is... " + coin );
System.out.print( "Would you like to flip again (y/n)? " );
again = keyboard.next();
} while (again.equals("y"));
System.out.println("Got tired???");
}
}
///This still works because its going to automatically do the do-while loop which then gives again a value causing it to go again.
Picture of the output