Blog Archives

Write a program that prints the sum of two random integers between 1 and 6 (such as you might get when rolling dice).

//TEST ** (double star) program
import java.lang.Math;

public class DicerollTEST{
public static void main(String[] args) {
int SIDES = 6;                                                                                //declares there 6 sides on a die and int SIDES
int a = 1 + (int) (Math.random() * SIDES);                       //Gives the random roll to one die
int b = 1 + (int) (Math.random() * SIDES);                      //Gives the random roll to the second die
int sum = a + b;                                                                            //Adds the sum of the two dice
System.out.println(sum);                                                       //Prints the sum of the 2 dice

%d bloggers like this: