Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

DiceRoller

import java.util.Random;

/**
 * Simulates rollling a pair of dice.
 * 
 * @author Sarah Joiner
 * @version September 13, 2017
 */
public class DiceRoller {
    public static void main(String[] args) {
        Random rand = new Random();
        
        // roll dice and compute sum
        int die1 = 1 + rand.nextInt(6);
        int die2 = 1 + rand.nextInt(6);
        int sum = die1 + die2;
        
        // output results
        System.out.println("First die: " + die1);
        System.out.println("Second dies "+ die2);
        System.out.println("The sum is " + sum + ".");
    }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.