Guest User

Untitled

a guest
May 27th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3.  
  4. public class DiceRolls {
  5.  
  6. /**
  7. * Jessica Wu
  8. * Mr. Benum
  9. * Practice
  10. * Jan 17
  11. */
  12. public static void main(String[] args) {
  13. // declare variables
  14. Random r = new Random();
  15. Scanner input = new Scanner(System.in);
  16.  
  17. int numDice;
  18. int numRolls;
  19. int ranOutcome = 0;
  20.  
  21. //get user input
  22. System.out.println("How many rolls?");
  23. numRolls = input.nextInt();
  24.  
  25. System.out.println("How many dice?");
  26. numDice = input.nextInt();
  27.  
  28. int diceLimit = numDice*6*numRolls;
  29. int [] outcomes = new int [diceLimit];
  30.  
  31. //get dice rolls, put in appropriate place in outcomes array
  32. for (int x = 0; x<=numRolls; x++) {
  33. for (int y = 0; y<=numDice; y++) {
  34. ranOutcome += (r.nextInt(6) + 1);
  35. System.out.println("Sum: " + ranOutcome);
  36. outcomes[ranOutcome] +=1;
  37. }
  38. }
  39.  
  40. //output
  41. for (int i = 2; i<diceLimit; i++) {
  42. System.out.println(i + ": " + outcomes[i]);
  43. }
  44. }
  45.  
  46. }
Add Comment
Please, Sign In to add comment