First question
20 Mobile phone number scrolling display randomly draw out a winning number;
static void BBB (string[] args)
{
string[] CellPhone = new string[] {"13012345678", "13109876543", "13287654678", "13309876789",
"13509878902", "13698374651", "13757893421", "13876561234", 13909876543 ",
"15034567438", "15111234795", "15894574839", "18210394857", "18302938475"};
Random rand = new Random ();
for (int i=0;i<50;i++)
{
System.Threading.Thread.Sleep (100); Slow down a bit.
int sub = rand. Next (cellphone.length); Randomly generates the subscript for an array.
string s = cellphone[sub]; The element values of the array are taken according to the subscript.
Console.clear (); Clear Screen
Console.WriteLine (s); Show
}
}
}
30 people vote, choose one out of 5 candidates.
int[] vote = new Int[5];
for (int i=0;i<30;i++)
{
Console.Write ("Please" + (i+1) + "Students Vote (0-4):");
int temp = Convert.ToInt32 (Console.ReadLine ());
if (temp <0 | | temp >4)
{
Console.WriteLine ("Invalidated");
Continue
}
Else
{
vote[temp]++;
}
}
Calculate the final ticket. int max = 0, maxsub = 0;
for (int i=0;i<vote. length;i++)
{
Show the number of votes for each candidate. Console.WriteLine ("No." + (i + 1) + "Number of votes for candidates is:" + vote[i]);
Calculates the maximum value. if (Vote[i] > Max)
{max = vote[i];
Maxsub = i;
}
}
Displays the final result. Console.WriteLine ("Final poll Result:" + (maxsub+1) + "candidate elected, the number of votes is" +max+ "ticket. ");
}
}
}
C # loop App mobile phone number The exercise of the squad Leader