/* Marty Stepp, CSE 142, Autumn 2008 Rolls two dice until a sum of 7 is reached. This second version uses a do/while loop, which performs its test at the end of each execution of its body. This means the body will run 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 tries = 0; int sum; do { // roll the dice once int roll1 = rand.nextInt(6) + 1; int roll2 = rand.nextInt(6) + 1; sum = roll1 + roll2; System.out.println(roll1 + " + " + roll2 + " = " + sum); tries++; } while (sum != 7); System.out.println("You won after " + tries + " tries!"); } }