Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners A Java program to simulate throwing a die
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Samith
A Java program to simulate throwing a die
2 Answer(s)      2 years and 7 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


Advertisement
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 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  hi friends how to make a java program for getting non prime odd numbers in a given series
java program
java program  Write a java program to do matrix addition operation On two given matrices
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 a java program to display array list and calculate the average of given array
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 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 create text area and display the various mouse handling events
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  . 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
Advertisements
 

 

 

DMCA.com