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;
/**
 * Rolls a pair of six sided dice
 * 
 * @author Jackson Sottile
 */
public class DiceRoller {
    
    public static void main(String[]args) {
        Random rand = new Random();//pseudo random numbers
        
        // roll the dice and compute the sum
        int die1 = 1 + rand.nextInt(6);
        //generates random int between 0(inclusive) and 6(exclusive)
        int die2 = 1 + rand.nextInt(6);
        int sum = die1 + die2;
        
        System.out.println("die 1: " + die1);
        System.out.println("die 2: " + die2);
        System.out.println("Sum = " + sum);
        
    }
     
}

Advertisements
Loading...

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