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.
/**
* Demonstrates how to create objects and initialize them
* with constructors.
*
* @author Xavier Char-Amato
*/
import java.util.Random;
public class Dice{
public static void main(String[] args){
Random rand = new Random();
int[] dice = new int[2];
dice[0] = 1 + rand.nextInt(6);
dice[1] = 1 + rand.nextInt(6);
int sum = 0;
for (int i=0; i<dice.length; i++){
System.out.println("Die #" + (i+1) +" "+ dice[i]);
sum += dice[i];
}
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