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.
import java.util.Random;
/*
* Simulates rolling a pair of dice
*
* @author Willy Ferreiras
*/
public class DiceRoller{
public static void main(String[] args){
Random rand = new Random();
// Random's nextInt method generates a random int, not including limit
int die1 = rand.nextInt(6) + 1;
int die2 = rand.nextInt(6) + 1;
int sum = die1 + die2;
System.out.println("Die 1: " + die1);
System.out.println("Die 2: " + die2);
System.out.println("Sum: " + sum);
}
}
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more