Advertisement
CamiloCastilla

Untitled

Dec 5th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. package com.company;
  2. import java.util.Scanner;
  3. import java.util.Random;
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner keyboard = new Scanner(System.in);
  8.         Random rng = new Random();
  9.         System.out.println("Would you like to flip a coin (y/n)?");
  10.         String again = keyboard.next();
  11.  
  12.         do {
  13.             int flip = rng.nextInt(2);
  14.             String coin;
  15.  
  16.             if ( flip == 1 )
  17.                 coin = "HEADS";
  18.             else
  19.                 coin = "TAILS";
  20.  
  21.             System.out.println( "You flip a coin and it is... " + coin );
  22.  
  23.             System.out.print( "Would you like to flip again (y/n)? " );
  24.             again = keyboard.next();
  25.         } while ( again.equals("y"));
  26.  
  27.  
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement