Ask your own question, for FREE!
Computer Science 34 Online
volpina:

Javascript helpppp? Write a program that rolls two dice until the user gets snake eyes. You should use a loop and a half to do this. Each round you should roll two dice (Hint: use the Randomizer!), and print out their values. If the values on both dice are 1, then it is called snake eyes, and you should break out of the loop. You should also use a variable to keep track of how many rolls it takes to get snake eyes. Sample Run: Rolled: 6 5 Rolled: 5 2 Rolled: 3 6 Rolled: 6 2 Rolled: 1 2 Rolled: 5 3 Rolled: 1 4 Rolled: 1 1 It took you 8 rolls to get snake eyes.

Arrow:

Let me come to your rescue This program simulates rolling a pair of dice until they come up snake eyes. It reports how many rolls were needed. public class SnakeEyes { public static void main(String[] args) { int die1, die2; // The values rolled on the two dice. int countRolls; // Used to count the number of rolls. countRolls = 0; do { die1 = (int)(Math.random()*6) + 1; // roll the dice die2 = (int)(Math.random()*6) + 1; countRolls++; // and count this roll } while ( die1 != 1 || die2 != 1 ); System.out.println("It took " + countRolls + " rolls to get snake eyes.");

volpina:

Ouu tyyy

Arrow:

what does that mean

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!