Monty374

RollDice

Nov 28th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. package dicerolls;
  2.  
  3.  
  4. import java.util.Scanner;
  5. import java.util.Random;
  6. public class DiceRolls {
  7. public static void main(String[] args) {
  8. int[] outcomes = new int[19];
  9. Scanner input = new Scanner(System.in);
  10. int numRolls;
  11. Random rand = new Random();
  12. int outcome;
  13.  
  14. /* prompt user for number of rolls */
  15. System.out.print("How many rolls? ");
  16. numRolls = input.nextInt();
  17.  
  18. /* roll dice and add to outcomes */
  19. for (int roll = 0; roll < numRolls; roll++) {
  20. outcome = (rand.nextInt(6) + 1) + (rand.nextInt(6) + 1) + (rand.nextInt(6) + 1);
  21. outcomes[outcome] += 1;
  22. }
  23.  
  24. /* show counts of outcomes */
  25. for (int i = 3; i <= 18; i++) {
  26. System.out.println(i + ": " + outcomes[i]);
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment