If you wanted to keep that one die rolling 20 times, you would do the
following:
/** oneDieByTwenty - generates one throw of one die
* uses a random number generator to do that
* and it rolls 20 times
**/
public class oneDieByTwenty
{
public static void main (String [] args)
{
double x; // holds the random number we will generate
int diceValue; // holds the value of the dice that we calculate from
the random number
int count;
for (count = 0; count
<20; count++)
{
x = Math.random(); // generates a number between 0 and 1
x = x *6; // multiplies that number times 6 so the number
will be from 0 to 5
diceValue = (int) x; // convert it to integer to chop off the decimal
portion
diceValue = diceValue +1; // with dice, we want 1-6, not 0-5, so we add
1
System.out.println ("The value of this die is " + diceValue);
}
}
}