Question
need help with dice excercise
For example, if we were writing a calendar program of some sort, we might very well use an array with 366 spots to hold the d
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Main.java E saved 1 import java.util.Scanner; 2 import java.util. Random; java version 1.8.0 31 Java (TM) SE Runtime Enviro

code:

import java.util.Scanner;

import java.util.Random;

class Main {

public static void main(String[] args) {

int counts[] = new int[]{0,0,0,0,0,0,0,0,0,0,0,0,0};

Scanner sc = new Scanner(System.in);

Random rand = new Random();

System.out.print("How many rolls you want to try : ");

int rolls = sc.nextInt();

int dice1,dice2;

for(int i=0;i<rolls;i++){

dice1 = rand.nextInt((6 - 1) + 1) + 1;

dice2 = rand.nextInt((6 - 1) + 1) + 1;

counts[dice1+dice2]+=1;

}

System.out.printf("\n\nTotal\tCount");

for(int i=2;i<13;i++){

System.out.printf("\n%5d\t%d",i,counts[i]);

}

}

}

Add a comment
Know the answer?
Add Answer to:
need help with dice excercise For example, if we were writing a calendar program of some...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in C please, Write the code to simulate rolling three dice and find the sum of...

    in C please, Write the code to simulate rolling three dice and find the sum of the top three faces. Repeat rolling the three dice 10,000 times. Use an array called frequency to have the count of each sum. Pass this array to a function that calculates the maximum number that appears in this array. Print this maximum in main.

  • Write a java program that simulates the rolling of four dice. The program should use random...

    Write a java program that simulates the rolling of four dice. The program should use random number generator to roll dice. The sum of the four values should then be calculated. Note that each die can show an integer value from 1 to 6, so the sum of the four values will vary from 4 to 24, with 14 being the most frequent sum and 4 and 24 being the least frequent sums. Your program should roll the dice 12,960...

  • ( Java Programming ) Write an application to simulate the rolling of two dice. The application...

    ( Java Programming ) Write an application to simulate the rolling of two dice. The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the values will vary from 2 to 12, with 7 being the most frequent sum, and 2 and 12...

  • please do it in C++ Write a program that simulates the rolling of two dice. The...

    please do it in C++ Write a program that simulates the rolling of two dice. The program should use rand to roll the first die and should use rand again to roll the second die. The sum of the two values should then be calculated. [Note: Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2and 12...

  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • Java programming Write a simulation of the Craps dice game. Craps is a dice game that...

    Java programming Write a simulation of the Craps dice game. Craps is a dice game that revolves around rolling two six-sided dice in an attempt to roll a particular number. Wins and losses are determined by rolling the dice. This assignment gives practice for: printing, loops, variables, if-statements or switch statements, generating random numbers, methods, and classes. Craps game rules: First roll: The first roll (“come-out roll”) wins if the total is a 7 or 11. The first roll loses...

  • hey, struggling with this assignment, wondering if if I could get some help. Here is the...

    hey, struggling with this assignment, wondering if if I could get some help. Here is the project details The following lists a Dice class that simulates rolling a die with a different number of sides. The default is a standard die with six sides. The rollTwoDice function simulates rolling two dice objects and returns the sum of their values. The srand function requires including cstdlib. my class ------------------------------------ class Dice { public: Dice(); DIce(int numSides); virtual int rollDice()const; protected: int...

  • (1 point) Using an if Statement In a Loop A common thing to do is to...

    (1 point) Using an if Statement In a Loop A common thing to do is to use variables to keep track of some sort of count. When used in a loop we count things very quickly. Scenario: If you roll a pair of dice, rolling a 12 (two sixes) is rare. How rare? If you were to roll a pair of dice 1,000 times, on average, how many times would it come up as 12? To figure this out, we...

  • Hello experts, I need help answering the following question and its sub-questions please. I use M...

    Hello experts, I need help answering the following question and its sub-questions please. I use MINITAB for my data. Please show your work to make it easier for understanding! will upvote! The duration of baseball games in the major league in the 2010 and 2011 seasons is uniformly distributed between 2.76 and 3.22 hours inclusive. We would like to simulate 10,000 samples of 30 game duration time and construct a 90% and 98% confidence interval for the mean duration of...

  • not precalc- stat #2. Use the Minitab to simulate 10,000 rolls of two dice. Find the...

    not precalc- stat #2. Use the Minitab to simulate 10,000 rolls of two dice. Find the number of times that the sum of the two dice is exactly 7. Based on that result, use the relative frequency approach to estimate the probability of getting a 7 when two dice are rolled. Compare this probability to the true probability and also compare this probability to your estimated probability in #1 when you rolled the dice 1000 times. What do you think...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT