// Tyler Rigsby, CSE 142 // Uses Random to roll a pair of dice until their sum is 7; // reports the number of rolls import java.util.*; public class RollDice { public static void main(String[] args) { Random rand = new Random(); int sum = 0; int count = 0; while (sum != 7) { // rand.nextInt(6) gives us 0-5; adding 1 gives 1-6 int dieA = rand.nextInt(6) + 1; int dieB = rand.nextInt(6) + 1; sum = dieA + dieB; count++; System.out.println("You rolled a " + dieA + " and a " + dieB + " which sum to " + sum); } System.out.println("It took " + count + " rolls to roll a 7"); } }