zoukankan      html  css  js  c++  java
  • C#第三节课(2)

    运算符

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace yunsuanfu
    {
    class Program
    {
    static void Main(string[] args)
    {
    //算术运算符
    //++ --
    //放置在变量名前面或者后面
    //int a = 1;
    //int b=a++;//int b=a;a=a+1;
    //int c=++a;//int a=a+1;c=a;
    //Console.WriteLine(a);

    //Console.ReadLine();

    //* / %
    //% 模 除商取余
    //int a = 10;
    //int b = 3;
    //Console.WriteLine(a%b);

    //+ -
    //int a = 3;
    //int b = 4;
    //Console.WriteLine(a - b);

    //关系运算符
    //> < >= <=
    //== !=
    //int a = 4;
    //int b = 6;
    //bool c = a < b;
    //Console.WriteLine(c);

    //逻辑运算符
    //&& 两个都满足
    //|| 至少有一个满足
    //! 若开始时是true,改为false
    //int a = 4;
    //int b = 7;
    //int c = 8;
    //bool d = a < b && a < c;
    //bool e = a < b || a < c;
    //Console.WriteLine(d);
    //Console.WriteLine(e);

    //条件运算符 ? :
    //int a = 3;
    //int b = 6;
    //string s = a < b ? "对,a<b" : "错,a>b";
    //int c = a > b ? 1 : 2;
    //Console.WriteLine(s);

    //赋值运算符
    //= += -= /= %=

    //int a = 3;
    //a += 2;//a=a+2;
    //a -= 5;//a=a-5;
    //a *= 2;//a=a*2;

    //Console.WriteLine(a);

    //条件运算符,练习
    //问,现在几点了。
    //输入小时数,判断是am还是pm
    //若是pm的,需要减去12小时进行打印报时

    //Console.Write("现在几点了");
    //int shi = int.Parse(Console.ReadLine());
    //if (shi > 0 && shi < 24)
    //{

    // string mm = shi > 12 ? "现在是pm" + (shi - 12) : "现在是am" + shi;

    // Console.WriteLine(mm);
    //}
    //else {
    // Console.WriteLine("您的输入有误");
    //}


    //输入一个100以内的数,判断这个数是否跟7有关
    //7的倍数 %
    //个位数是7 %
    //十位数是7 /

    for ( int i ; ; )
    {
    Console.WriteLine("请输入一个100以内的整数:");
    int a = int.Parse(Console.ReadLine());
    Console.WriteLine("是七的倍数么?" + (a % 7 == 0));
    Console.WriteLine("是七的倍数么?" + (a % 10 == 7));
    Console.WriteLine("是七的倍数么?" + (a / 10 == 7));
    if ((a % 7 == 0) || (a % 10 == 7) || (a / 10 == 7))
    {
    Console.WriteLine("拍手");
    }
    else
    {
    Console.WriteLine("喊" + a);
    }

    }
    Console.ReadLine();

    }
    }
    }

    分类

    符号

    解释

    优先级

     

    算数

    ++   --

    加加   减减

    由高到低,即执行顺序由上到下.圆括号的优先级最高)

    */%

    乘  除  取余

    +  -

    加  减

    关系    

    >  <    >=   <=   

    大于 小于 大于等于 小于等于

    ==     !=

    等于  不等于

     

    逻辑

    &&

    与(并且)

    ||

    !

    非(注:优先级在此表的最顶层)

    条件运算符

    ?:

    惟一的一个三元运算符  如果

    赋值

    =    +=  -=  *=    /=   %=

     如:x-=4.x=x-4;

    1:前++和后++的区别(-- 一样)

    int a = 10,b=a++;

    Console.WriteLine("a=" + a);

    Console.WriteLine("b=" + b);结果:a=11  b=10

    int a = 10, b=++a;

    Console.WriteLine("a=" + a);

    Console.WriteLine("b=" + b);结果:a=11  b=11

    2.条件运算符:

    例子:x=(x>12)?1:2;  //假如x>12,那么就返回1,否则就返回2

     

    好好学习,天天向上
  • 相关阅读:
    React class & function component 的区别
    Webpack 4 + React + Typescript 搭建启动模版
    JavaScript的数据类型及其检测
    react SyntheticEvent 合成事件机制
    数组的排序
    Ajax 和 Ajax的封装
    go 结构的方法总结
    go 结构的方法2
    go struct 的方法1
    go 函数闭包
  • 原文地址:https://www.cnblogs.com/xiongxiaobai/p/5247817.html
Copyright © 2011-2022 走看看