Home > Back-end >  A Java problem, I just learned a little, no level
A Java problem, I just learned a little, no level

Time:10-12

Topic: throw two dice, calculate throw several times, at least two dice value is 5, the number of output must be at least throw,
The following is a part of me to write, I know this is wrong, hurt, I feel is at least 11 times, now I want to ask: how do I do it the next time you enter that part number + 1, is several times and enter the number of + 1 with different firstDie secondDie, I here is totally random, how to eliminate calculated number of that kind of situation before, the number is between 2-12 times 11 times did not repeat, 11, the final output (private marseille, is a little confusing, but I really can't write T ^ T)
Int firstDie secondDie;
Int I=0, r=0;
Do {
FirstDie=throwDice ();
SecondDie=throwDice ();
If (firstDie!=secondDie)
{
R +=(firstDie + secondDie);
i++;
}
} while (r!=10);
System. Out. Println (" at least throw "+ I +" ");
}
Static int throwDice ()
{
int result;
Result=(int) (Math. The random () * 6) + 1;
return result;
  • Related