Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package apcs;
- import java.util.*;
- public class TwoDiceSum {
- public static void main(String[] args) {
- double count = 0.0;
- int rollvalue = 0;
- double dice1 = 0.0;
- double dice2 = 0.0;
- Scanner input = new Scanner(System.in);
- int desiredSum = input.nextInt();
- int numberRolls = input.nextInt();
- for (int i = 0; i <= numberRolls; i++) {
- dice1 = (Math.random()*6) + 1;
- dice2 = (Math.random()*6) + 1;
- rollvalue = (int) (dice1 + dice2);
- if (rollvalue == desiredSum) {
- count++;
- }
- }
- double unroundedprobability = count / (double)(numberRolls);
- double probability = Math.round(unroundedprobability * 100.0) / 100.0;
- System.out.println();
- System.out.println("Enter desired sum of two dice: Enter number of rolls: probability: " + probability);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement