Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Solution {
  4. public static void main(String args[] ) {
  5. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  6. Scanner sc = new Scanner(System.in);
  7. int tosses = sc.nextInt();
  8. int heads = sc.nextInt();
  9. double simulations =100000;
  10. double counter = 0;
  11. for(int i = 0; i < simulations; i++)
  12. {
  13. int total = 0;
  14. for(int j = 0; j < tosses;j++)
  15. {
  16. if(Math.random()>.5)
  17. {
  18. total++;
  19.  
  20. }
  21. }
  22. if(total>= heads)
  23. {
  24. counter++;
  25. }
  26. }
  27. System.out.println(Math.round ((counter*100)/simulations));
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement