First:
Console. writeline ( " 100 throwing experiments: " ); // Prompt information
Random randomnum = New Random (); // Create a random number
Int Num1 = 0 ; // Define the number of times 1 appears
Int Num2 = 0 ; // Define the number of times 2 appears
Int Num3 = 0 ; // Define the number of times 3 appears
Int Num4 = 0 ; // Define the number of times that 4 appears
Int Num5 = 0 ; // Define the number of times that 5 appears
Int Num6 = 0 ; // Define the number of times that 6 appears
For ( Int I = 1 ; I <= 100 ; I ++)// For statement Loop
{
Int Num = 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 times {0} is: {1} " , I, num );
}
Console. writeline ( " 1 appears {0} Times " , Num1 );
Console. writeline ( " 2 appears {0} Times " , Num2 );
Console. writeline ( " 3 appears {0} Times " , Num3 );
Console. writeline ( " 4 {0} Times " , Num4 );
Console. writeline ( " 5 appears {0} Times " , Num5 );
Console. writeline ( " 6 appears {0} Times " , Num6 );
// Verify if it is 100 times
Int Sum = num1 + num2 + num3 + num4 + num5 + num6;
Console. writeline (SUM );
Second:
Namespace _ 2011. _ 12. _ 3
{
Class Program
{
Static Void Main ( String [] ARGs)
{
Int [] Count = New Int [ 7 ];
Random randomnum = New Random ();
Int Num = 0 ;
For ( Int I = 0 ; I < 100 ; I ++)
{
Num = randomnum. Next ( 1 , 7 );
Count [num] ++;
}
Console. writeline ( " 1 appears: {0} " , Count [ 1 ]);
Console. writeline ( " 2: {0} " , Count [ 2 ]);
Console. writeline ( " 3: {0} " , Count [ 3 ]);
Console. writeline ( " 4: {0} " , Count [ 4 ]);
Console. writeline ( " 5: {0} " , Count [ 5 ]);
Console. writeline ( " 6: {0} " , Count [ 6 ]);
Console. writeline (" {0} throws in total! " , Count [ 1 ] + Count [ 2 ] + Count [ 3 ] + Count [ 4 ] + Count [ 5 ] + Count [ 6 ]);
}
}
}
Third:
Class Program
{
Static Void Main ( String [] ARGs)
{
// Calculates the number of times that a throw occurs between 1 and 6 times.
Int [] Array = New Int [ 7 ]; // Array [1] represents face = 1
Random rannum = New Random ();
For ( Int Counter = 0 ; Counter <= 6000 ; Counter ++)
{
++ Array [rannum. Next ( 1 , 7 )]; // The default array [] = 0, so when array [1] appears once, + 1;
}
For ( Int Face =1 ; Face <= 6 ; Face ++)
{
Console. writeline ( " Face {0} is {1} " , Face, array [face]); // The output value of array [] is the number of occurrences.
}
}
}