Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Random;
- public class DiceRolls {
- /**
- * Jessica Wu
- * Mr. Benum
- * Practice
- * Jan 17
- */
- public static void main(String[] args) {
- // declare variables
- Random r = new Random();
- Scanner input = new Scanner(System.in);
- int numDice;
- int numRolls;
- int ranOutcome = 0;
- //get user input
- System.out.println("How many rolls?");
- numRolls = input.nextInt();
- System.out.println("How many dice?");
- numDice = input.nextInt();
- int diceLimit = numDice*6*numRolls;
- int [] outcomes = new int [diceLimit];
- //get dice rolls, put in appropriate place in outcomes array
- for (int x = 0; x<=numRolls; x++) {
- for (int y = 0; y<=numDice; y++) {
- ranOutcome += (r.nextInt(6) + 1);
- System.out.println("Sum: " + ranOutcome);
- outcomes[ranOutcome] +=1;
- }
- }
- //output
- for (int i = 2; i<diceLimit; i++) {
- System.out.println(i + ": " + outcomes[i]);
- }
- }
- }
Add Comment
Please, Sign In to add comment