Assignment #70

Code

    /// Name: Jonathan Stine
    /// Period: 5
    /// Program Name: Flip Again?
    /// File Name: FlipAgain.java
    /// Date Finished: 1/19/16
    
    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's: " + coin );
    
    			System.out.print( "Would you like to flip again (y/n)? " );
    			again = keyboard.next();
    		} while ( again.equals("y") );
    	}
    }
    
    /// 3. Because "again" is given a value before the condition is evaluated, the program still works.

    
 
    

Code Output