Advertisement
Yuvalxp8

Coin Toss

Jan 28th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. public class CoinToss {
  2.     public static void main(String[] args) {
  3.         double flip;
  4.         String coinside;
  5.         int shirHeads = 0;
  6.         int leeHeads = 0;
  7.         int counter = 0;
  8.         while(shirHeads < 3 && leeHeads < 3) {
  9.             flip = Math.random();
  10.             if(flip > 0.5)
  11.             {
  12.                 coinside = "Tails";
  13.             }
  14.             else
  15.             {
  16.                 coinside = "Heads";
  17.             }
  18.             if (counter % 2 == 0) {
  19.                 System.out.println("Shir flipped " + coinside);
  20.                 if(coinside.equals("Heads"))
  21.                 {
  22.                     shirHeads++;
  23.                 }
  24.             }
  25.             else
  26.             {
  27.                 System.out.println("Lee flipped " + coinside);
  28.                 if(coinside.equals("Heads"))
  29.                 {
  30.                     leeHeads++;
  31.                 }
  32.             }
  33.             counter++;
  34.         }
  35.         if(shirHeads == 3)
  36.         {
  37.             System.out.println("Shir gets to start! She flipped heads " + shirHeads + " times");
  38.         }
  39.         else
  40.         {
  41.             System.out.println("Lee gets to start! She flipped heads " + leeHeads + " times");
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement