Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Solution {
- public static void main(String args[] ) {
- /* Enter your code here. Read input from STDIN. Print output to STDOUT */
- Scanner sc = new Scanner(System.in);
- int tosses = sc.nextInt();
- int heads = sc.nextInt();
- double simulations =100000;
- double counter = 0;
- for(int i = 0; i < simulations; i++)
- {
- int total = 0;
- for(int j = 0; j < tosses;j++)
- {
- if(Math.random()>.5)
- {
- total++;
- }
- }
- if(total>= heads)
- {
- counter++;
- }
- }
- System.out.println(Math.round ((counter*100)/simulations));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement