编写一个掷骰子100次的程序,打出各种点数的出现次数

int num1=0, num2=0, num3=0, num4=0, num5=0, num6=0;
            Random random = new Random();
            for (int i = 0; i < 100; i++)
            {
                 int num = random.Next(1, 7);
                switch (num) { 
                    case 1:
                        num1++;
                        break;
                    case 2:
                        num2++;
                        break;
                    case 3:
                        num3++;
                        break;
                    case 4:
                        num4++;
                        break;
                    case 5:
                        num5++;
                        break;
                    case 6:
                        num6++;
                        break;
                }
                
            }
            Console.WriteLine(num1);
            Console.WriteLine(num2);
            Console.WriteLine(num3);
            Console.WriteLine(num4);
            Console.WriteLine(num5);
            Console.WriteLine(num6);

你可能感兴趣的:(C#常见题型)