• 选择语句2


    段点:用于调试;

    选择语句:if  else   switch   case;

    循环语句:do   for   foreach   while;

    跳转语句:break   continue   default   return;

    异常语句:try-catch-finally;

    for (int i = 1/*初始值*/; i <= 20/*循环条件(条件表达)*/; i++/*状态改变*/)

    (for循环可直接按Tob键)

    换行   ; =Console.ReadLine;                   

     Console.Write("请输入年份");
    int a = int.Parse(Console.ReadLine());
    if (a % 400 == 0 || (a % 100 != 0 && a % 4 == 0))
    {
    Console.Write("这是闰年");
    }
    else
    {
    Console.Write("不是闰年");*/
    //输入姓名、成绩输出级别、80-100优秀,60-79一般,0-59继续努力//
    //输入年月日,输出这一天是这年的第多少天. 输入一元二次方程的三个参数,判断方程有无实根//
    /* Console.WriteLine("请输入姓名");
    string a=Console.ReadLine();
    Console.WriteLine("请输入成绩");
    int b = int.Parse(Console.ReadLine());
    if((b<=100)&&(b>=80))
    {
    Console.WriteLine(a + "优秀");
    }
    else if((b>=60&&b<=79))
    {
    Console.WriteLine(a+"一般");
    }
    else
    {
    Console.WriteLine (a+"继续努力");
    }
    Console.ReadLine ();*/
    /* 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))
    {
    Console.WriteLine("输入的年份不正确!y应该在1759-9999之间");
    }
    else
    {
    if (!(m >= 1 && m <= 12))
    {
    Console.WriteLine("输入的月份不正确!m应该在1-12之间");
    }
    else
    {
    if ((m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) && (!(d >= 1 && d <= 31)))
    {
    Console.WriteLine("1,3,5,7,8,10,12月要在1-31的范围内");
    }

    else if ((m == 4 || m == 6 || m == 9 || m == 11) && (!(d <= 1 && d >= 30)))
    {
    Console.WriteLine("4,6,9,11月要在1-30的范围内");
    }

    else
    {
    if (m == 2 && (y % 400 == 0 || (y % 100 != 0 && y % 4 == 0)) && (!(d >= 1 && d <= 29)))
    {
    Console.WriteLine("闰年二月1-29");
    }
    else if (m == 2 && (y % 400 == 0 || (y % 100 != 0 && y % 4 == 0)) && (!(d >= 1 && d <= 28)))
    {
    Console.WriteLine("平年二月1-28");
    }
    else
    {
    Console.WriteLine("日期正确");

    int sumday = 0;
    if (y % 400 == 0 || (y % 100 != 0 && y % 4 == 0))
    {
    if (m == 1)
    sumday += d;
    if (m == 2)
    sumday += 31 + d;
    if (m == 3)
    sumday += 31 + 29 + d;
    if (m == 4)
    sumday += 31 + 29 + 30 + d;
    if (m == 5)
    sumday += 31 + 29 + 31 + 30 + d;
    if (m == 6)
    sumday += 31 + 29 + 31 + 30 + 31 + d;
    if (m == 7)
    sumday += 31 + 29 + 31 + 30 + 31 + 30 + d;
    if (m == 8)
    sumday += 31 + 29 + 31 + 30 + 31 + 30 + 31 + d;
    if (m == 9)
    sumday += 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + d;
    if (m == 10)
    sumday += 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + d;
    if (m == 11)
    sumday += 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + d;
    if (m == 12)
    sumday += 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + d;
    }
    else
    {
    if (m == 1)
    sumday += d;
    if (m == 2)
    sumday += 31 + d;
    if (m == 3)
    sumday += 31 + 28 + d;
    if (m == 4)
    sumday += 31 + 28 + 30 + d;
    if (m == 5)
    sumday += 31 + 28 + 31 + 30 + d;
    if (m == 6)
    sumday += 31 + 28 + 31 + 30 + 31 + d;
    if (m == 7)
    sumday += 31 + 28 + 31 + 30 + 31 + 30 + d;
    if (m == 8)
    sumday += 31 + 28 + 31 + 30 + 31 + 30 + 31 + d;
    if (m == 9)
    sumday += 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + d;
    if (m == 10)
    sumday += 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + d;
    if (m == 11)
    sumday += 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + d;
    if (m == 12)
    sumday += 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + d;
    }
    Console.WriteLine("这天是这一年的第{0}天", sumday);
    }
    }
    }
    Console.ReadLine();*/


    Random r=new Random();
    int shu=r.Next(3);//int shu=r.Next(3);
    Console.WriteLine("0-包袱,1-剪刀,2-石头");
    if(shu==0)
    {
    Console.WriteLine("电脑出包袱");
    }
    else if(shu==1)
    {
    Console.WriteLine("电脑出剪刀");
    }
    else
    {
    Console.WriteLine("电脑出石头");
    }
    Console.ReadLine();


    /*int renwin = 0;
    int cmpwin = 0;

    int ren = -1;
    int cmp = -1;
    //输入
    ren = Convert.ToInt32(Console.ReadLine());
    Random rand = new Random();
    cmp = rand.Next(3);

    //判断输出
    if (ren == 0) //0-布,1-剪刀,2-石头
    {
    if (cmp == 0)
    {
    Console.WriteLine("平局");
    }
    else if (cmp == 1)
    {
    Console.WriteLine("Computer Win!");
    cmpwin++;
    }
    else
    {
    Console.WriteLine("Human Win!");
    renwin++;
    }
    }
    else if (ren == 1)
    {
    if (cmp == 0)
    {
    Console.WriteLine("Computer Win!");
    cmpwin++;
    }
    else if (cmp == 1)
    {
    Console.WriteLine("平局");
    }
    else
    {
    Console.WriteLine("Human Win!");
    renwin++;
    }
    }
    else if (ren == 2)
    {
    if (cmp == 0)
    {
    Console.WriteLine("Computer Win!");
    cmpwin++;
    }
    else if (cmp == 1)
    {
    Console.WriteLine("Human Win!");
    renwin++;
    }
    else
    {
    Console.WriteLine("平局");
    }
    }
    else
    {
    Console.WriteLine("请按套路出拳");
    }


    //输入
    ren = Convert.ToInt32(Console.ReadLine());
    cmp = rand.Next(3);
    if (ren == 0) //0-布,1-剪刀,2-石头
    {
    if (cmp == 0)
    {
    Console.WriteLine("平局");
    }
    else if (cmp == 1)
    {
    Console.WriteLine("Computer Win!");
    cmpwin++;
    }
    else
    {
    Console.WriteLine("Human Win!");
    renwin++;
    }
    }
    else if (ren == 1)
    {
    if (cmp == 0)
    {
    Console.WriteLine("Computer Win!");
    cmpwin++;
    }
    else if (cmp == 1)
    {
    Console.WriteLine("平局");
    }
    else
    {
    Console.WriteLine("Human Win!");
    renwin++;
    }
    }
    else if (ren == 2)
    {
    if (cmp == 0)
    {
    Console.WriteLine("Computer Win!");
    cmpwin++;
    }
    else if (cmp == 1)
    {
    Console.WriteLine("Human Win!");
    renwin++;
    }
    else
    {
    Console.WriteLine("平局");
    }
    }
    else
    {
    Console.WriteLine("请按套路出拳");
    }


    ren = Convert.ToInt32(Console.ReadLine());
    cmp = rand.Next(3);
    if (ren == 0) //0-布,1-剪刀,2-石头
    {
    if (cmp == 0)
    {
    Console.WriteLine("平局");
    }
    else if (cmp == 1)
    {
    Console.WriteLine("Computer Win!");
    cmpwin++;
    }
    else
    {
    Console.WriteLine("Human Win!");
    renwin++;
    }
    }
    else if (ren == 1)
    {
    if (cmp == 0)
    {
    Console.WriteLine("Computer Win!");
    cmpwin++;
    }
    else if (cmp == 1)
    {
    Console.WriteLine("平局");
    }
    else
    {
    Console.WriteLine("Human Win!");
    renwin++;
    }
    }
    else if (ren == 2)
    {
    if (cmp == 0)
    {
    Console.WriteLine("Computer Win!");
    cmpwin++;
    }
    else if (cmp == 1)
    {
    Console.WriteLine("Human Win!");
    renwin++;
    }
    else
    {
    Console.WriteLine("平局");
    }
    }
    else
    {
    Console.WriteLine("请按套路出拳");
    }


    //.......
    if (renwin > cmpwin)
    {
    Console.WriteLine("Ren YingLe");

    }
    else if (renwin == cmpwin)
    {
    Console.WriteLine("Ping Ju");
    }
    else
    {
    Console.WriteLine("Computer YingLe");
    }

    Console.ReadLine();

    }
    }
    }
    Console.ReadLine();*/

    /* int renwin = 0;
    int dnwin = 0;
    for (;; )
    {
    Random r = new Random();
    int dn = r.Next(3);
    Console.Write("请出拳:0-包袱,1-剪刀,2-石头");
    int ren = int.Parse(Console.ReadLine());
    if(dn-ren==-1||dn-ren==2)
    {
    Console.Write("电脑输了,人赢了");
    }
    else if(dn==ren)
    {
    Console.Write("平局");
    }
    else
    {
    Console.Write("你输了,电脑赢了");
    dnwin++;
    }

    }
    if (dnwin==2||renwin==2)
    {
    break;
    }
    else if (dnwin==2)
    {
    Console.Write("你输了");
    }
    else
    {
    Console.Write("你赢了");
    }
    Console.ReadLine();*/


    /* Console.WriteLine("请输入变量a的值");
    int a = int.Parse(Console.ReadLine());
    Console.WriteLine("请输入变量b的值");
    int b = int.Parse(Console.ReadLine());
    Console.WriteLine("请输入变量c的值");
    int c = int.Parse(Console.ReadLine());
    if (a == 0)
    {
    Console.WriteLine("不是一元二次方程");
    }
    else
    {
    if (a != 0 && b * b - 4 * a * c > 0)
    {
    Console.WriteLine("一元二次方程有两个不相等的实数根");
    }
    else if (a != 0 && b * b - 4 * a * c == 0)
    {
    Console.WriteLine("一元二次方程有一个实数根");
    }
    else
    {
    Console.WriteLine("一元二次方程无实数根");
    }
    }
    Console.ReadLine();*/
    }
    }
    }
    }

    for循环

    Console.WriteLine ("请输入一个数");

    int n=int.Parse (Console.ReadLine());
    int b=0
    for (int i = 1; i <= n; i++)
    {
    if(n%i==0)
    {
    b++;
    }
    }
    if(b==2);
    {
    Console.WriteLine("这个数是质数");
    }
    else
    {
    Console.WriteLine("这个数不是质数");
    }
    Console.ReadLine();

    /* Console.WriteLine("请输入一个数");
    int n = int.Parse("Console.ReadLine");*/
    /* Console.WriteLine("请输入一个数");
    int m = int.Parse("Console.ReadLine");
    int sum = 1;
    for (int n= 0; n <=m; n ++)
    {
    int s = 1;
    for (int i = 0; i <= n; i++)
    {
    s = s * i;
    }
    sum += s;
    }
    Console.WriteLine("阶乘的和为{0}", sum);

    Console.ReadLine();*/

    穷举
    /* int count = 0;
    for (int i = 1; i <= 20; i++)
    {
    for (int r = 1; r <= 50; r++)
    {
    for (int e = 1; e <= 33; e++)
    {
    if (i*5 + r*2 + e*3 == 100)
    {
    Console.WriteLine("100元正好买{0}种牙膏,{1}种牙刷,{2}种肥皂", i, r, e);
    count++;
    }
    }
    }
    }
    Console.WriteLine("共有{0}种可能",count);*/

    /* int count=0;
    for (int p = 1; p <=13; p++)
    {
    for (int q = 1; q <=66 ; q++)
    {
    for (int s = 1; s <=100 ; s++)
    {
    if(p*15+q*3+s*2==200)
    {
    Console.WriteLine("200元可以买{0}种羽毛球拍,{1}种球,{2}种水",p,q,s);
    count++;
    }
    }
    }
    }
    Console.WriteLine("共有{0}种可能",count);
    Console.ReadLine();*/


    /* int ct = 0;
    int xt=0;
    int yt = 1;
    int sum=0;
    for (int i =2;i <=24; i++)
    {
    ct=xt+ct;
    xt=yt;
    yt=ct;
    sum=ct+xt+yt ;
    Console.WriteLine("第{0}个月的成兔{1}小兔{2}幼兔{3}总数{4}",i,ct,xt,yt,sum);

    }
    Console.ReadLine();*/

    }
    }
    }

  • 相关阅读:
    C# NewtonJson Serialize and deserialize
    C# bubble sort,selection sort,insertion sort
    C# 7
    C# aggregateexception flatten innerexceptions
    C# monitor keyboard and mouse actions based on MouseKeyHook.
    C# monitor keyboard and print pressed key
    svn命令行
    正则表达式
    对象的浅拷贝跟深拷贝
    conso.log占位符
  • 原文地址:https://www.cnblogs.com/yg6405816/p/5342846.html
Copyright © 2020-2023  润新知