Ask your own question, for FREE!
Computer Science 18 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!
Latest Questions
RAVEN69: My drawing so far is actually fire
1 week ago 9 Replies 2 Medals
PureSoulless: is staying at your friend's house while you're homeless legal.
2 weeks ago 5 Replies 1 Medal
whyjustwhy: i did that one TV girl trend with blake (aka @ShadowKid3)
1 week ago 12 Replies 2 Medals
whyjustwhy: i did that one TV girl trend with blake (aka @shadowkid3)
2 weeks ago 3 Replies 0 Medals
whyjustwhy: yo guys he can watch me sleep now (ignore dora)
3 weeks ago 24 Replies 1 Medal
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!