/* CSE 142, Autumn 2007, Marty Stepp This program simulates the rolling of two dice until a sum of 7 is reached. Expected output: 2 + 4 = 6 3 + 5 = 8 5 + 6 = 11 1 + 1 = 2 4 + 3 = 7 You won after 5 tries! */ import java.util.*; // for Random public class Roll { public static void main(String[] args) { Random randy = new Random(); // two ints, one for each of two dice [1, 6] int die1 = 0; int die2 = 0; int tries = 0; while (die1 + die2 != 7) { // roll die1 = randy.nextInt(6) + 1; die2 = randy.nextInt(6) + 1; System.out.println(die1 + " + " + die2 + " = " + (die1 + die2)); tries++; } System.out.println("You won after " + tries + " tries!"); } }