import java.util.*; // Simulates rolling two dice until their sum is 7, // and keeps track of the nubmer of tries public class Dice { public static void main(String[] args) { Random rand = new Random(); int sum = 0; // priming the loop (dummy value) can be anything but 7 int tries = 0; while (sum != 7) { tries++; int die1 = rand.nextInt(6) + 1; // random num between 1-6 int die2 = rand.nextInt(6) + 1; // random num between 1-6 sum = die1 + die2; System.out.println(die1 + " + " + die2 + " = " + sum); } System.out.print("tries: " + tries); } }