Conditional Statement Instance

Source: Internet
Author: User

Judge three numbers who are to large:

Static voidMain (string[] args) {Console.WriteLine ("Please enter the first number:"); intA =Convert.ToInt32 (Console.ReadLine ()); Console.WriteLine ("Please enter a second number:"); intb =Convert.ToInt32 (Console.ReadLine ()); Console.WriteLine ("Please enter a third number:"); intc =Convert.ToInt32 (Console.ReadLine ()); if(A >=b) {if(A >=c) {Console.WriteLine ("the three largest numbers are:"+a); }                Else{Console.WriteLine ("the three largest numbers are:"+c); }            }            Else            {                if(b >=c) {Console.WriteLine ("three of the largest are"+b); }                Else{Console.WriteLine ("three of the largest are"+c); }            }        }

To determine the parity of a number:

 Static voidMain (string[] args) {Console.Write ("Enter a number:"); intA =int.                       Parse (Console.ReadLine ()); if(a%2==0) {Console.Write ("This number is even ."); }            Else{Console.Write ("This number is odd .");                   } console.readline (); }  

To judge leap years:

Static voidMain (string[] args) {Console.WriteLine ("Please enter the year:"); intYear =int.            Parse (Console.ReadLine ()); if(Year% -==0|| Year%4==0&& Year%4!=0) {Console.Write ( year+"is a leap year"); }            Else{Console.Write ( year+"It's common year ."); }        }

Mobile Customer Service:

Static voidMain (string[] args) {Console.WriteLine ("Check the telephone rate by 1, check the flow according to 2, manual service Press 3, Business processing Press 4,");intA =Convert.ToInt32 (Console.ReadLine ());Switch(a) { Case 1: {Console.WriteLine ("you have a lot of charges, no recharge."); Break;} Case 2: {Console.WriteLine ("flow can also support"); Break;} Case 3: {Console.WriteLine ("Please wait while the manual service is full"); Break;} Case 4: {Console.WriteLine ("Sorry, I can't handle it"); Break;}default: {Console.WriteLine ("you entered the wrong"); Break;}}}

The game then chooses the hero:

 Static voidMain (string[] args) {Random a=NewRandom (); intb = A.next (5); stringhero; Switch(b) { Case 1: {Hero="Ezreal";  Break; }                 Case 2: {Hero="Lacus";  Break; }                 Case 3: {Hero="Galen";  Break; }                 Case 4: {Hero="Tim Mo";  Break; }                default: {Hero="Tristana";  Break; }} Console.WriteLine ("the heroes you choose are:"+ Hero +", please be prepared to start"); }

Conditional Statement Instance

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.