我对上面那个仁兄的代码优化了一下。。。。。。
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace test
- {
- class Program
- {
- static void Main(string[] args)
- {
- Random ra = new Random();
- int[] count={0,0,0,0,0,0};
- int temp = 0;
- for (int i = 1; i <= 100; i++)
- {
- temp = ra.Next(1, 7);
- count[--temp]++;
- }
- Console.WriteLine("1出现{0}次,2出现{1}次,3出现{2}次,4出现{3}次,5出现{4}次,6出现{5}次", count[0], count[1], count[2], count[3], count[4], count[5]);
- Console.Read();
- }
- }
- }
复制代码 |