Assignment #70
Code
/// Name: Mahima Choudhary
/// Period: 6
/// Program Name: Flip Again?
/// File Name: FlipAgain.java
/// Date Finished: 1/4/2015
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 == 3 )
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") );
}
}
// the program will still work even when the string again doesnt have a value before the do-while loop because the loop doesn't need to meet the parameters before running
Picture of the output