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)