运算符 与 分支语句:if ,else if,else;switch case

分支语句:

if        else if       else      ;    switch          case

--如何使用 if  else if  else:

            Console.WriteLine("请你出拳");      --输出【请你出拳】
            int a = Convert.ToInt32(Console.ReadLine());      --定义一个变量a
            Random i = new Random();      --随机数
            int x = i.Next(3);              --变量x可以随机出0-3的数
            if ((a - x == 1) || (a - x == -2))
            {
                Console.WriteLine("电脑=" + x);
                Console.WriteLine("人赢了");
            }
            else if (x==a)
            {
                Console.WriteLine("电脑=" + x);
                Console.WriteLine("平局");
            }
            else
            {
                Console.WriteLine("电脑=" + x);
                Console.WriteLine("人输了");
            }

--如何使用switch case:

     int a = Convert.ToInt32(Console.ReadLine());    --定义一个变量a
            switch (a)      --切记switch括号里只能放一个变量
            {
                case 1:
                    Console.WriteLine("星期一");
                    break;     --每个case后面结束的时候都要加一个break不然会显示语句错误
                case 2:
                    Console.WriteLine("星期二");
                    break;
                case 3:
                    Console.WriteLine("星期三");
                    break;
                case 4:
                    Console.WriteLine("星期四");
                    break;
                case 5:
                    Console.WriteLine("星期五");
                    break;
                case 6:
                    Console.WriteLine("星期六");
                    break;
                case 7:
                    Console.WriteLine("星期日");
                    break;
                default:
                    Console.WriteLine("你输入的可能不正确");
                    break;

            }

运算符:

    数学运算符:+ - * / %

    比较运算服:> < >= <= != ==

    逻辑运算符:&&(并且) ||(或者) !(反效果)

    赋值运算服: = += -= *= /= %=

    条件运算服:(比较表达式)?(语句一):(语句二)

原文地址:https://www.cnblogs.com/2041388565m/p/4158289.html