Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. Scanner keyboard = new Scanner(System.in);
  7. Random rng = new Random();
  8.  
  9. String again;
  10. // 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.
  11. do
  12. {
  13. int flip = 1+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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement