The scissors of the IF statement

Source: Internet
Author: User

To generate a random number using a computer:

Random rand = new Random ();//Make a random generator, random(); a random generator seed can be placed inside the parentheses, this seed can only be an integer (int)
int n = rand. Next (10); n represents a random number that is generated between 0-9

Case: A little game to do scissors

0---Scissors 1---stone 2---cloth

Idea: A computer randomly generates a number, and the number of people entering a 0--2

1, if the person out of the punch minus the computer random number is 1 or-2, then the person won

2, if the person out of the punch minus the computer random number is 0, then the draw

3, if the person out of the punch minus the computer random number is-1 or 2, then the computer won

Console.WriteLine ("please take a punch:"); stringHuman =Console.ReadLine (); Random Rand=NewRandom ();//build a random number generator            intn = rand. Next (3);//randomly generates an integer less than 3            stringcomputer; intRen; if(n = =0) {Computer="Scissors"; }            Else if(n = =1) {Computer="Stone"; }            Else{Computer="cloth"; }            if(Human = ="Scissors"|| Human = ="Stone"|| Human = ="cloth")//To define the punch of the person, set the 0,1,2 with the computer generated comparison {if(Human = ="Scissors") {ren=0; }                Else if(Human = ="Stone") {ren=1; }                Else{ren=2; } Console.WriteLine (Human+"VS"+computer); intJieguo = ren-N; if(Jieguo = =1|| Jieguo = =-2) {Console.WriteLine ("brother, you won! "); }                Else if(Jieguo = =0) {Console.WriteLine ("A Draw! "); }                Else{Console.WriteLine ("you're too much food! "); }            }            Else{Console.WriteLine ("Roll Duzi! "); }

The scissors of the IF statement

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.