/* Marty Stepp, CSE 142, Autumn 2009 Rolls two dice until a sum of 7 is reached. This second version of the program uses a do/while loop because we know that the loop must execute at least once. Example output: 2 + 4 = 6 3 + 5 = 8 5 + 6 = 11 1 + 1 = 2 4 + 3 = 7 You won after 5 tries! */ import java.util.*; public class Dice2 { public static void main(String[] args) { Random rand = new Random(); int rolls = 0; int sum; do { // do one roll int die1 = rand.nextInt(6) + 1; // 1-6 int die2 = rand.nextInt(6) + 1; // 1-6 sum = die1 + die2; rolls++; System.out.println(die1 + " + " + die2 + " = " + sum); } while (sum != 7); System.out.println("You won after " + rolls + " tries!"); } }