This is complete working code for the Simulation and Modelling Assignment.
If u have to use it, make sure u UNDERSTAND it and then EDIT it
your own way.
THE DICE THROW CODE:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package diceroll;
import java.util.Random;
public class DiceRoll
{
public static void main( String[] args)
{
Random faces = new Random(); // Generates random numbers
int[] array = new int[ 7]; // Declares the array
//Roll the die 1,000 times
for ( int i = 1; i <=1000; i++ )
{
++array[ 1 + faces.nextInt ( 6 ) ];
System.out.printf( "%s%10s\n", "Face\t","Frequency\t","Percen
}
// outputs array values
for ( int face = 1; face < array.length; face++ )
{
int percentage=(array[face]*100)/
System.out.printf( "%4d%10d%10d\n", face, array[ face ],percentage);
}
}
}
No comments:
Post a Comment