Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CoinToss {
- public static void main(String[] args) {
- double flip;
- String coinside;
- int shirHeads = 0;
- int leeHeads = 0;
- int counter = 0;
- while(shirHeads < 3 && leeHeads < 3) {
- flip = Math.random();
- if(flip > 0.5)
- {
- coinside = "Tails";
- }
- else
- {
- coinside = "Heads";
- }
- if (counter % 2 == 0) {
- System.out.println("Shir flipped " + coinside);
- if(coinside.equals("Heads"))
- {
- shirHeads++;
- }
- }
- else
- {
- System.out.println("Lee flipped " + coinside);
- if(coinside.equals("Heads"))
- {
- leeHeads++;
- }
- }
- counter++;
- }
- if(shirHeads == 3)
- {
- System.out.println("Shir gets to start! She flipped heads " + shirHeads + " times");
- }
- else
- {
- System.out.println("Lee gets to start! She flipped heads " + leeHeads + " times");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement