Console.WriteLine ("the experiment was thrown 100 times:");//Prompt Information
Random Randomnum =NewRandom ();//Create a random number
intNUM1 =0;//define the number of occurrences of 1
intnum2 =0;//define the number of occurrences of 2
intNUM3 =0;//define the number of occurrences of 3
intNUM4 =0;//define the number of occurrences of 4
intNUM5 =0;//define the number of occurrences of 5
intNUM6 =0;//define the number of occurrences of 6
for(inti =1; I <= -; i++)//For statement Loop
{
intnum = Randomnum.next (1,7);//define a variable to accept random numbers
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;
}
default:
Break;
}
Console.WriteLine ("the number of {0} times is: {1}", I, NUM);
}
Console.WriteLine ("1 has occurred {0} times", NUM1);
Console.WriteLine ("2 has occurred {0} times", num2);
Console.WriteLine ("3 has occurred {0} times", num3);
Console.WriteLine ("4 has occurred {0} times", NUM4);
Console.WriteLine ("5 has occurred {0} times", NUM5);
Console.WriteLine ("6 has occurred {0} times", NUM6);
//verify whether it is 100 times
intsum = num1 + num2 + num3 + num4 + num5 + num6;
Console.WriteLine (sum);
The second method of solution:
namespace_2011._12._3
{
classProgram
{
Static voidMain (string[] args)
{
int[] Count =New int[7] ;
Random Randomnum =NewRandom ();
intnum =0;
for(inti =0; I < -; i++)
{
num = Randomnum.next (1,7);
Count[num] + +;
}
Console.WriteLine ("1 occurrences are: {0}", count[1]);
Console.WriteLine ("2 occurrences are: {0}", count[2]);
Console.WriteLine ("3 occurrences are: {0}", count[3]);
Console.WriteLine ("4 occurrences are: {0}", count[4]);
Console.WriteLine ("5 occurrences are: {0}", count[5]);
Console.WriteLine ("6 occurrences are: {0}", count[6]);
Console.WriteLine ("altogether threw {0} times! ", count[1]+count[2]+count[3]+count[4]+count[5]+count[6]);
}
}
}
Throw 100 throws calculate the number of occurrences of each number C # source case attached to the second simple solution