Assignment #70

Code

    /// Gian Adoremos
    /// Period: 7
    /// Program Name: Seventieth Program
    /// File Name: Flipagain.java
    /// Date Finished: 12/7/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;
                /// it still works because it doesnt need to be compiled before the do statement
        
        		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

Assignment 70