# 4, C # basic finishing (if statement classic exercises)

Source: Internet
Author: User

1, use if to determine whether the input is the space bar Method: (Console.readkey () the use of)

`Consolekeyinfo Readkey = console.readkey (); Console.WriteLine (Readkey. Key.tostring ()); if " SPACEBAR " )         Console.WriteLine (" space ");`

2, with If......else to determine whether it is a leap year (leap years to be divisible by 4, * Note: If the year can be divisible by 100, but also divisible by 400 is the leap)

`Console.WriteLine ("Please enter the year:");intYear =int. Parse (Console.ReadLine ());if(Year%4==0){    if(Year% -==0)    {        if(Year% -==0) {Console.WriteLine ("Yes"); }        ElseConsole.WriteLine ("No"); }    ElseConsole.WriteLine ("Yes");}ElseConsole.WriteLine ("No");`

3. If......else If......else Enter a number within a 1~100 to determine whether it is related to 7

`Console.WriteLine ("Please enter a number within the 1~100");intShu =int. Parse (Console.ReadLine ());if(Shu >=1&& Shu <= -){    if(shu%Ten==7) Console.WriteLine ("Yes"); Else if(shu%7==0) Console.WriteLine ("Yes"); Else if(shu/Ten==7) Console.WriteLine ("Yes"); ElseConsole.WriteLine ("No");}Else{Console.WriteLine ("Input Error");}`

4, input a,b,c, to find the solution of a two-time equation

`Console.WriteLine ("Please enter A,b,c"); intA =int.            Parse (Console.ReadLine ()); intb =int.            Parse (Console.ReadLine ()); intc =int.            Parse (Console.ReadLine ()); if(A = =0&& B! =0)            {                Doublex = (Double) (-C)/b; Console.WriteLine ("There is a real roots {0}", x); }            Else if(A = =0&& b = =0) {Console.WriteLine ("A, B are zero, no real roots"); }            Else            {                DoubleDe =SQR (b * B-4Ac); if(De = =0)                {                    Doublex = (Double) (-B)/(2*a); Console.WriteLine ("There are two equal real roots, x1=x2={0}", x); }                Else if(De <0) {Console.WriteLine ("this equation has no solution"); }                Else                {                    DoubleX1 = (Double) ((-B) + math.sqrt (DE))/(2*a); Doublex2 = (Double) ((-B)-math.sqrt (DE))/(2*a); Console.WriteLine ("There are two real roots, x1={0},x2={1}", X1,X2); }            }            `

4, C # basic finishing (if statement classic exercises)

Related Keywords:
Related Article

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.