Share on Google+Share on Google+

Samith
A Java program to simulate throwing a die
2 Answer(s)      4 years and 11 months ago
Posted in : Java Beginners

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

Ads

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
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
Advertisements
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
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... The Tutorial illustrate an example from 'PHP SQL Die'. To understand and grasp the example
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
jQuery '.live' & '.die' Mouse events
jQuery '.live'  & '.die' Mouse events In this tutorial ,we will discuss about how to  remove an event using 'die'... click , click on blue button to see effect of die event </font><
Java Throw Built-in Exception
Java Throw Built-in Exception In this section we are discussing about throwing of built-in exceptions in Java. In Java throw and throws keywords are used... will demonstrate you about how to use throw keyword in Java to throw the exception
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
java program for
java program for   java program for printing documents,images and cards
Java Program
Java Program  A Java Program that print the data on the printer but buttons not to be printed
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  write a program to print 1234 567 89 10
java program
java program  Write a program to create an applet and display The message "welcome to java
Java Program
Java Program  java program to insert row in excel sheet after identifying an object
java program
java program  write java program for constructor,overriding,overriding,exception handling
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  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 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  how to write an addition program in java without using arithematic operator
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 demonstrate the concept of various possible exceptions arising in a Java Program and the ways to handle them.  ... in Java
Throwing an Exception in JSTL
Throwing an Exception in JSTL          In this program we are going to show you...; The code of the program is given below:       <
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   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
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 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
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads