Assignment #X
Code
///jack newsom
///period 5
///program FlipAgain
///file FlipAgain.java
///date completed 10/13/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();
System.out.println("Would you like to flip a coin (y/n) ?");
String again = keyboard.next();
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") );
}
}
Picture of the output