Advertisement
Guest User

This will flip a coin untill it lands on its side

a guest
Dec 6th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class SideLandingExperiment {
  4.  
  5.     static boolean coinOnSide = false;
  6.     static int timesTried = 0;
  7.  
  8.     public static void main(String[] args) {
  9.  
  10.         while (coinOnSide == false) {
  11.             Random rand = new Random();
  12.             timesTried++;
  13.             System.out.println("Try number" + timesTried);
  14.             int result = rand.nextInt(6001);
  15.  
  16.             if (result == 0) {
  17.                 System.out.println("side");
  18.                 System.out.println("It took " + timesTried
  19.                         + " tries to get the coin to land on its side");
  20.                 coinOnSide = true;
  21.             }
  22.  
  23.             else if (result > 0) {
  24.  
  25.                 if (result < 3000) {
  26.  
  27.                     System.out.println("heads");
  28.                 }
  29.             }
  30.             if (result > 3000) {
  31.                 System.out.println("tails");
  32.  
  33.             }// ends if
  34.         }// ends loop
  35.     }// ends method main
  36. }// ends Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement