Rolling a Die:
/*Use JAVA program to simulate rolling a die. The method, nextInt(n), will return a number between 0 (inclusive) and n (exclusive). That is, by calling nextInt(6), you will receive one of the following. 0, 1, 2, 3, 4, and 5. */
import java.util.Random;
public class CastDie
{
public static void main(String[] args)
{
Random generator = new Random();
int x, n =30, sum = 0;
System.out.println("The average of cast a die "+ n + " times: ");
for(int i=0; i<n; i++)
{
x= generator.nextInt(6) + 1;
System.out.print(x + " ");
sum += x;
}
System.out.println("is " + sum /(double) n); //To convert int to double before dividing each other.
}
}






