A Java program to simulate throwing a die

A Java program to simulate throwing a die (singular of dice) 6000 times and store the frequency with which each face of the die is uppermost after each throw in an array.

A couple of sample outputs follow: 1: 1020 2: 1015 3: 990 4: 1036 5: 941 6: 998

1: 984 2: 1016 3: 967 4: 1028 5: 985 6: 1020

View Answers

April 26, 2012 at 4:02 PM

mate, you cant cheat on your assignment1 FIT1002 by getting other people to code it for you. You should know this by now. If you have any problems you should go see your tutor. Lucky this doesnt get taken against you


April 26, 2012 at 5:10 PM

import java.util.Random;

public class DiceRolling
{
    public static void main( String[] args)
    {
        Random randomNumbers = new Random(); 
        int[] array = new int[ 7 ]; 
        int dice;
        for ( int roll = 1; roll <=6000; roll++ )
        {
            dice = 1 + randomNumbers.nextInt ( 6 );
            ++array[dice]; 
        }
         System.out.println("Face     Frequency");
        for ( int face = 1; face < array.length; face++ )
          System.out.println( face+"\t "+ array[ face ] );

    }     
}

The above code throw a dice 6000 times and and store the frequency with which each face of the die after each throw in an array.









Related Tutorials/Questions & Answers:
A Java program to simulate throwing a die
A Java program to simulate throwing a die  A Java program to simulate throwing a die (singular of dice) 6000 times and store the frequency with which each face of the die is uppermost after each throw in an array. A couple
ModuleNotFoundError: No module named 'simulate'
ModuleNotFoundError: No module named 'simulate'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'simulate' How to remove the ModuleNotFoundError: No module named 'simulate
Advertisements
ModuleNotFoundError: No module named 'die'
ModuleNotFoundError: No module named 'die'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'die' How to remove the ModuleNotFoundError: No module named 'die' error
ModuleNotFoundError: No module named 'event-simulate'
ModuleNotFoundError: No module named 'event-simulate'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'event-simulate' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'js.jquery_simulate'
ModuleNotFoundError: No module named 'js.jquery_simulate'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'js.jquery_simulate' How to remove the ModuleNotFoundError: No module
ModuleNotFoundError: No module named 'js.jquery_simulate'
ModuleNotFoundError: No module named 'js.jquery_simulate'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'js.jquery_simulate' How to remove the ModuleNotFoundError: No module
ModuleNotFoundError: No module named 'simulate-replay'
ModuleNotFoundError: No module named 'simulate-replay'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'simulate-replay' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'event-simulate'
ModuleNotFoundError: No module named 'event-simulate'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'event-simulate' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'js.jquery_simulate'
ModuleNotFoundError: No module named 'js.jquery_simulate'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'js.jquery_simulate' How to remove the ModuleNotFoundError: No module
ModuleNotFoundError: No module named 'simulate-numbers-package'
ModuleNotFoundError: No module named 'simulate-numbers-package'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'simulate-numbers-package' How to remove
java program - Java Beginners
java program  I worte out this program that was supposed to simulate a die rolling and then the program printing out each roll, the program also... wrote out most of the program , I don't know how to get it to print out the number
ModuleNotFoundError: No module named 'todo-or-die'
ModuleNotFoundError: No module named 'todo-or-die'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'todo-or-die' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'todo-or-die'
ModuleNotFoundError: No module named 'todo-or-die'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'todo-or-die' How to remove the ModuleNotFoundError: No module named '
java util date - Time Zone throwing illegal argument exception
java util date - Time Zone throwing illegal argument exception  ...()); The date object is not getting created for IST time zone. Java is throwing an Illegal Argument Exception Why is the second SOP always throwing
Will Google ever die?
Will Google ever die?  Hi, I am beginner in Data Science and machine... die? Try to provide me good examples or tutorials links so that I can learn the topic "Will Google ever die?". Also tell me which is the good
Will YouTube ever die?
Will YouTube ever die?  Hi, I am beginner in Data Science... ever die? Try to provide me good examples or tutorials links so that I can learn the topic "Will YouTube ever die?". Also tell me which is the good
why it is throwing classCastException.
why it is throwing classCastException.   public class Redwood extends Tree { public static void main(String[] args) { new Redwood().go(); } void go() { go2(new Tree(), new Redwood()); go2((Redwood) new
PHP SQL Die
PHP SQL Die       PHP SQL Die results when there is a connection failure. The die( ) function prints..._TO_REPLACE_1 The Tutorial illustrate an example from 'PHP SQL Die'. To understand
Write a program in java...
Write a program in java...  Hi, friends Please, can you help me? Q1: Write a program in java to simulate a calculator. Your program should take two... to enter an integer number. Write a program in java to find the factorial
Exceptional Example in Java
it to the program by throwing the object of exception method. The Exception Object states... Exceptional Example in Java       When an error occurs in a method, Java creates an object
java program for
java program for   java program for printing documents,images and cards
a Java program
a Java program    Write a Java program to print even numbers from 2 to 1024? Write a Java program to print ? My Name is Mirza? 100 times? Write a Java program to print Fibonacci Series? Write a Java program to reverse a number
Java Program
Java Program  A Java Program that print the data on the printer but buttons not to be printed
java program
java program  write a program to print 1234 567 89 10
java program
java program  Write a program to demonstrate the concept of various possible exceptions arising in a Java Program and the ways to handle them.  ... in Java
java program
java program  write java program for constructor,overriding,overriding,exception handling
java program
java program  how to write an addition program in java without using arithematic operator
java program
java program  write a java program to display array list and calculate the average of given array
java program
java program  write a java program to display array list and calculate the average of given array
Java Program
Java Program  java program to insert row in excel sheet after identifying an object
java program
java program  java program to implement the reflection of a particular class details like constructor,methods and fields with its modifiers
java program
java program  Write a java program to do matrix addition operation On two given matrices
java program
java program  Write a java program to find the number of Positive numbers in m* n matrix
java program
java program  Write a program to create an applet and display The message "welcome to java
java program
java program  hi friends how to make a java program for getting non prime odd numbers in a given series
java program
java program   Write a program to find the difference between sum of the squares and the square of the sums of n numbers
java program
java program  write a program to create text area and display the various mouse handling events
java program
java program  . Write a program which performs to raise a number to a power and returns the value. Provide a behavior to the program so as to accept any type of numeric values and returns the results
Java program
Java program  Write a program which performs to raise a number to a power and returns the value. Provide a behavior to the program so as to accept any type of numeric values and returns the results
java program
java program  Develop the program calculatePipeArea. It computes the surface area of a pipe, which is an open cylinder. The program accpets three values: the pipes inner radius, its length, and the thickness of its wall
java program
java program  . Develop the program calculatePipeArea. It computes the surface area of a pipe, which is an open cylinder. The program accpets three values: the pipes inner radius, its length, and the thickness of its wall
program in java
program in java  write a reverse program in java using string buffer.the input and out put as follows. input- hi good mornig out put-ih doog ginrom
java program
java program  write a java program to compute area of a circle.square,rectangle.triangle,volume of a sphere ,cylinder and perimeter of cube using method over riding
java program
java program  write a java program to compute area of a circle.square,rectangle.triangle,volume of a sphere ,cylinder and perimeter of cube using method over riding
java program
java program   A B C D E F F E D C B A A B C D E E D C B A A B C D D C B A A B C C B A A B B A A A java program to display above triangle
java program
java program  write a program to create server and client such that server receives data from client using BuuferedReader and sends reply to client using PrintStream
java program
java program  write a program to read 10 numbers from user and store it in a array. display the maximum n minimum number in the array
java program
java program  write a java program to read a file which hold email address validate email address tohave formate @.* and replace all .com email address
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array