Assignment #62
Code
/// Name: Sam Wilson
/// Period: 6
/// Program Name: flip1
/// File Name: flip1.java
/// Date Finished: 1/3/2015
import java.util.Random;
import java.util.Scanner;
public class flip1
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random rng = new Random();
//Do while allows a line to be run for the first time and over again until the desired command is recieved. While allows a line to run until a desired command from a previous line is recieved.
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") );
}
}
Picture of the output