Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Random;
- public class Main {
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- Random rng = new Random();
- String again;
- // if we remove the value of the string after the code is made into a 'do-while' loop, the code still runs as the 'do' part will always run regardless of any variables that are affected afterwards.
- do
- {
- int flip = 1+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"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement