static void Main(string[] args)
{
int[] val = { 0, 0, 0, 0, 0, 0 };
Random rval = new Random();
for (int i = 1; i <= 100; i++)
{
if (rval.Next(1, 7) == 1) val[0] += 1;
if (rval.Next(1, 7) == 2) val[1] += 1;
if (rval.Next(1, 7) == 3) val[2] += 1;
if (rval.Next(1, 7) == 4) val[3] += 1;
if (rval.Next(1, 7) == 5) val[4] += 1;
if (rval.Next(1, 7) == 6) val[5] += 1;
}
Console.WriteLine("The number 1 occures {0} times. ", val[0]);
Console.WriteLine("The number 2 occures {0} times. ", val[1]);
Console.WriteLine("The number 3 occures {0} times. ", val[2]);
Console.WriteLine("The number 4 occures {0} times. ", val[3]);
Console.WriteLine("The number 5 occures {0} times. ", val[4]);
Console.WriteLine("The number 6 occures {0} times. ", val[5]);
Console.ReadKey();
}
楼主试试我的代码,可以解决此问题。 |