Do-While Loops #70 (So... Do-whiles are like the senate, less rules than the house.)

Code

/// Name: Amir Salehi
/// Period: 7
/// Program Name:Flip Again
/// File Name:FlipAgain.java
/// Date Finished: 12/17/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 == 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") );
    
    //3.) If the stirng has been deleted the code will continue to go into a paradox.
		
		
	
}
}


    

Picture(s) of the output

Assignment 7

Back to Homepage