Example: stone scissors cloth. Do it with an array. More difficult to understand, mainly logical thinking

Source: Internet
Author: User

Random r = new Random (); Random definition of two persons

string[] S1 = new string[] {"Scissors", "stone", "cloth"};

string[] s2 = new string[] {"Scissors", "stone", "cloth"}; Randomly define an array of two people

String JG;

while (true)

{

int sj1 = R.next (0, 3); 0 for scissors, 1 for stone, 2 for cloth

int sj2 = R.next (0, 3);

if (sj1 = = sj2)

{

JG = "A Out is" + s1[sj1] + ", B out is" + s2[sj2] + ", the result is a draw";

}

else if (sj1 > Sj2)

{

if (sj1 = = 0 && sj2 = = 2)//If random 1 out of scissors, random 2 out of cloth

{

JG = "A out of is" + s1[sj1] + ", B out of is" + s2[sj2] + ", the result is B victory";

}

Else

{

JG = "A out of is" + s1[sj1] + ", B out of is" + s2[sj2 "+" result is a victory ";

}

}

Else

{

if (sj1 = = 2 && sj2 = = 0)//If random 1 out of cloth, random 2 out of scissors

{

JG = "A out of is" + s1[sj1] + ", B out of is" + s2[sj2] + ", the result is B victory";

}

Else

{

JG = "A out of is" + s1[sj1] + ", B out of is" + s2[sj2] + ", the result is B victory";

}

}

Console.WriteLine (JG);

Console.ReadLine ();

Example: stone scissors cloth. Do it with an array. More difficult to understand, mainly logical thinking

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.