C#基础(语句 if else)

语句:顺序,条件,循环

If ()//关系表达式

{}//语句

if(){}else{}//if(){}//if(){}else if(){}else{}

Console.WriteLine("年份:");

            int Y = int.Parse(Console .ReadLine ());

            Console.WriteLine("月份:");

            int M = int.Parse(Console.ReadLine());

            Console.WriteLine("日期 :");

            int D = int.Parse(Console.ReadLine());

            if ((!(Y >= 1759 && Y <= 9999)) || ((M == 1 || M == 3 || M == 5 || M == 7 || M == 8 || M == 10 || M == 12) && (!(D > 0 && D <= 31))) || (!(M > 0 && M <= 12)) || (M == 4 || M == 6 || M == 9 || M == 11) && (!(D > 0 && D <= 30)))

          

            { Console.WriteLine("输入日期错误"); }

            if ((Y % 400 == 0 || (Y % 100 != 0 && Y % 4 == 0) && M == 2 && (!(D > 0 && D <= 29))) || (M == 2 && (!(D > 0 && D <= 28))))

            { Console.WriteLine("输入日期错误"); }

            else

            {

                int t = 0;

                if (Y % 400 == 0 || (Y % 100 != 0 && Y % 4 == 0))

                {

                    if (M == 1) { t += D; }

                    if (M == 2) { t += 31 + D; }

                    if (M == 3) { t += 31 + 29 + D; }

                    if (M == 4) { t += 31 + 29 + 31 + D; }

                    if (M == 5) { t += 30 + 29 + 31 + 30 + D; }

                    if (M == 6) { t += 30 + 29 + 31 + 30 + 31 + D; }

                    if (M == 7) { t += 30 + 29 + 31 + 30 + 31 + 30 + D; }

                    if (M == 8) { t += 30 + 29 + 31 + 30 + 31 + 30 + 31 + D; }

                    if (M == 9) { t += 30 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + D; }

                    if (M == 10) { t += 30 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + D; }

                    if (M == 11) { t += 30 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + D; }

                    if (M == 12) { t += 30 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + D; }

                }

                else

                {

                    if (M == 1) { t += D; }

                    if (M == 2) { t += 31 + D; }

                    if (M == 3) { t += 31 + 28 + D; }

                    if (M == 4) { t += 31 + 28 + 31 + D; }

                    if (M == 5) { t += 30 + 28 + 31 + 30 + D; }

                    if (M == 6) { t += 30 + 28 + 31 + 30 + 31 + D; }

                    if (M == 7) { t += 30 + 28 + 31 + 30 + 31 + 30 + D; }

                    if (M == 8) { t += 30 + 28 + 31 + 30 + 31 + 30 + 31 + D; }

                    if (M == 9) { t += 30 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + D; }

                    if (M == 10) { t += 30 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + D; }

                    if (M == 11) { t += 30 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + D; }

                    if (M == 12) { t += 30 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + D; }

                    

                }

               Console.WriteLine("这是第" + t + "天");*/

            /* Console.WriteLine("输入一元二次方程:ax*x+bx+c=0");

             Console.Write("a=");

             double a = double.Parse(Console.ReadLine());

             Console.Write("b=");

             double b = double.Parse(Console.ReadLine());

             Console.Write("c=");

             double c = double.Parse(Console.ReadLine());

             double e = b * b - 4 * a * c;

             if (a == 0)

             { Console.WriteLine("这不是一个一元二次方程"); }

             else

             {

                 Console.WriteLine("这是一个一元二次方程");

                 if (e > 0)

                 {

                     double x1 = -b + Math.Sqrt(e) / (2 * a);

                     double x2 = -b - Math.Sqrt(e) / (2 * a);

                     Console.WriteLine("有两个不同的实根");

                     Console.WriteLine("两个根分别是:x1=" + x1.ToString() + "  x2=" + x2.ToString());

                 }

                 else if (e == 0)

                 {

                     Console.WriteLine("有两个相同的实根");

                     double x1 = -b + Math.Sqrt(e) / (2 * a);

                     double x2 = -b - Math.Sqrt(e) / (2 * a);

                     Console.WriteLine("两个根分别是:x1=x2=" + x1.ToString());

                 }

                 else

                 { Console.WriteLine("没有实根"); }*/

            /*  Console.WriteLine("0-石头,1-剪刀,2-布");

       随机数 Random r =new Random();

       Int shu  =r.Next();

              

          Console.Write("b  ");

          int b = int.Parse(Console.ReadLine());

              Random r = new Random();

              int a = r.Next(3);

              int c = 0;

              int d = 0;

                

              if (b <= 2 && b >= 0)

              {

                  if (a == 0) { Console.WriteLine("电脑出石头"); }

                  else if (a == 1) { Console.WriteLine("电脑出剪刀"); }

                  else { Console.WriteLine("电脑出布 "); }

                  if (a == b) { Console.WriteLine("平局"); }

                  else if ((b == 0 && a == 1) || (b == 2 && a == 0) || (b == 1 && a == 2)) { Console.WriteLine("你赢了"); c++; }

                  else if ((b == 0 && a == 2) || (b == 1 && a == 0) || (b == 2 && a == 1)) { Console.WriteLine("你输了"); d++; }

              }

              else { Console.WriteLine("输入错误 "); }*/

            /* int a = 0;

                 for (int i = 1; i <= 100; i++)

                 {

                     a += i;

               

                 }

                 Console.WriteLine(a);

               */

            /* Console.WriteLine("输入数字:");

             int n = int.Parse(Console .ReadLine ());

             for (int i = 1; i <=n; i++)

             {

                  Console.WriteLine(i);

             }*/

            /*int a = 0;

                   for (int i = 0; i <=100; i=i +2)

                   {

                    

                       a += i;

                   }

               

               Console.WriteLine(a);*/

            /* Console.WriteLine("0-石头,1-剪刀,2-布");

           

           

             Random r = new Random();

             int a = r.Next(3);

             int H = 0;

             int C = 0;

             if (a == 0) { Console.WriteLine("电脑出石头"); }

             else if (a == 1) { Console.WriteLine("电脑出剪刀"); }

             else { Console.WriteLine("电脑出布 "); }

             for (int i =1; i <= 3; i++)

             {

              

             Console.Write("b   ");

             int b = int.Parse(Console.ReadLine());

           

             if (b == 0)

             {

                 if (a == 0) { Console.WriteLine("平局"); }

                 if (a == 1) { Console.WriteLine("你赢了"); H++; }

                 if (a == 2) { Console.WriteLine("电脑赢了"); C++; }

             }

             else if (b==1)

             {

                 if (a == 0) { Console.WriteLine("电脑赢了"); C++; }

                 if (a == 1) { Console.WriteLine("平局"); }

                 if (a == 2) { Console.WriteLine("你赢了"); H++; }

             }

             else if (b == 2)

             {

                 if (a == 0) { Console.WriteLine("你赢了"); H++; }

                 if (a == 1) { Console.WriteLine("电脑赢了"); C++; }

                 if (a == 2) { Console.WriteLine("平局"); }

             }}

         if(H>C){Console.WriteLine("你赢了");}

        else if (C > H) { Console.WriteLine("电脑赢了"); }

       else { Console.WriteLine("平局"); }*/

            /*  int a = 0;

              for (int i = 1; i <= 100; i ++)

              {

                  if (i % 2 == 0)

                  { a += i; }

              }

              Console.WriteLine(a);*/

原文地址:https://www.cnblogs.com/wallan/p/5343858.html