Assignemnt #70 and Flip Again?
Code
/// Name: Kyle Ivy
/// Period: 5
/// Program Name: FlipAgainS
/// File Name: FlipAgain.java
/// Date Finished: 1/5/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;
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") );
}
}
/*
1. ok
2. ok
3. It still works because the code inside the do-while loop will run first, another again prompt will show..
*/
prog70.PNG