Advertisement
devankransteuber

Untitled

Mar 5th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import java.util.concurrent.ThreadLocalRandom;
  2.  
  3.  
  4. public class CoinFlip {
  5.  
  6.  
  7.    
  8.     public static void main(String args[]){
  9.         int randomNumber;
  10.         int oneCount = 0;
  11.         int twoCount = 0;
  12.         double total;
  13.         double averageOne=0, averageTwo=0;
  14.        
  15.    
  16.    
  17.    
  18.     for(int i=0; i<20; i++){
  19.         randomNumber = ThreadLocalRandom.current().nextInt(1, 2 + 1);
  20.         if(randomNumber == 1){
  21.             oneCount++;
  22.         }else{
  23.             twoCount++;
  24.         }
  25.        
  26.         System.out.print(oneCount);
  27.    
  28.         averageOne = (oneCount / (oneCount + twoCount)) * 100;
  29.         averageTwo = (twoCount / (oneCount + twoCount)) * 100;
  30.        
  31.         System.out.println(averageOne);
  32.         System.out.println(averageTwo);
  33.    
  34.        
  35.        
  36.     }
  37.    
  38.    
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement