Assignemnt # and
Code
///Name: Dakota Donahue
///Period: 5
///Project Name:
///File Name:
///Date: 3/10/2016
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 = ("y");
while ( again.equals("y") )
{
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();
}
}
}
// When the code is reverted to the way that it was before, the variable is not initialized an the while loop cannot run for the first time.